3

The code below fails to detect a single instance of the occurance. =O Whats wrong? =\

How do I detect the following lines (which begin with a newline) that begin with an asterisk ? I'm at a loss. This isn't behaving as I expected.

$text ="Nothing here to detect...though it is the first line.
* '' [[test]]
* Another line that starts with an asterisk 
** yet another...though it has two...but who cares about the 2nd one?";


$t = preg_match_all('#^\*.*#', $text, $match);
echo "found=".$t."\n";
print_r($match);
j08691
  • 204,283
  • 31
  • 260
  • 272
Timothy Martens
  • 678
  • 4
  • 17

1 Answers1

7

add the m modifier to specify that this has a multi line subject like #^\*.*#m

http://php.net/manual/en/reference.pcre.pattern.modifiers.php

Jonathan Kuhn
  • 15,279
  • 3
  • 32
  • 43