You could go about it like this (roughly):
- Read the log file into a line-by-line array with "file()", or into a string with "file_get_contents()".
- Loop through the array checking each element, or check the string, for the presence of the UA string, using "strpos()".
- If it's found, go back to bed.
- Otherwise, using "fopen($file, 'a')", "fwrite()", and "fclose()", add your new log line.
If you want to update (e.g. to increment a count) a found UA line: use the "file()" method, alter the specific array element (line), then open the file with "w" and write the entire array back to the file.