Finding Lines with an Odd Number of Quotes
<?php
$file = fopen("data.txt", "r") or die("Cannot open file!\n");
$lineNbr = 0;
while ($line = fgets($file, 1024)) {
$lineNbr++;
if (preg_match("/^[^\"]*\"([^\"]*|([^\"]*\"[^\"]*\"[^\"]*)*)$/", $line)) {
echo "Found match at line " . $lineNbr . ": " . $line;
}
}
fclose($file);
?>
Related examples in the same category