Re: preg_match fails to fill $matches
| From: | Jason k Larson | Date: | Wed, 05 Mar 2003 17:09:23 +0000 |
| Subject: | Re: preg_match fails to fill $matches | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-138311@lists.php.net to get a copy of this message | ||
What is the value of $trigger_string in your $ts variable?
Also, try removing the 's' from outside the pattern matching in $ts. You might get back some useful information.
usage: pmatch [ -cfghilnv ] '/pattern/' [ file ] ...
-c : show only line count for each file
-f : show only filenames in output
-g : greedy matching
-h : supress filenames from output
-i : ignore case
-l : show entire line instead of just what matched
-n : show line numbers in output
-s : supress error messages about missing or unreadable files
-t : do not trim whitespace from begin/end of lines
-v : show lines that do NOT match pattern
--
Jason k Larson
{R}ichard Ashton wrote:
On Wed, 5 Mar 2003 10:21:30 -0500, 1LT John W. Holmes wrote:The full cod in the loop is. $cnt = 0; while(!feof($fp)) {$ts = '/(' . $trigger_string .')/is'; echo "trigger_string is $ts <br>"; $matches = array();What's your actual code? How are you looking for the match in $matches? >If something was matched, then it'll be there.$hit = array();In the loop $hit[] = preg_match ($ts, $line_in,$matches); Now the $hit array fills up correctly, if the trigger string is on the line just read in, putting 1 or 0 in $hits. But the string that triggered the match is not put in $matches. The manual says it should be.// Get body $line_in = fgets($fp,4096); $cnt++; // looking for the other end of the marker found above if (substr($line_in,2,strlen($line_in)-5) != $marker ) { $body = $body . $line_in; $hit[] = preg_match ($ts, $line_in,$matches); $line[] = $line_in; $char = substr($line_in,0,1); $quote[] = preg_match ($qs, $char); } if (strpos($line_in, $marker) > 0 ) { break; }} Later on in the code after the loop I do echo "printing array matches <br>"; print_r ($matches);echo "<br>"; echo "printing array hit <br>"; print_r ($hit); echo "printing array quote <br>"; print_r ($quote); echo "printing array lins <br>"; print_r ($line); $lcnt = count($line); echo "cnt of line array is $lcnt <br>"; $hcnt = count($hit); echo "cnt of hit array is $hcnt <br>"; $qcnt = count($quote); echo "cnt of quote array is $qcnt <br>"; $mcnt = count($matches); echo "cnt of matches array is $mcnt <br>"; the arrays $hit and $line and $quote all print data, and all the count($array) print a value except the $matches array and count are empty. {R}