There is a trouble that it is not goes well at reading one line regular expression.
I would like to code if only one dot contained in a line, issue an alert.
$file = fopen("test.txt", "r"); if($file){ while($line = fgets($file)){ if(preg_match('/^.$/', $line)){ echo "please write again.<br>"; } else { echo "OK<br>"; } } } fclose($file);
Regular expression does not work well in this code.
add half-width dot in the regular expression
if($file){ while($line = fgets($file)){ if(preg_match('/^..$/', $line)){ echo "please write again.<br>"; } else { echo "OK<br>"; } } }
A half-size dot in a regular expression means an arbitrary one character.