0

I get this:

  $p= <<<'EOD'
stuff
more
EOD;
  print (preg_match ('~^stuff$~m', $p)); // expected 1, got 0

despite

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

the "start of line" and "end of line" constructs match immediately following or immediately before any newline in the subject string, respectively

EDIT: This is in a standard Windows text file.

ChrisJJ
  • 2,191
  • 1
  • 25
  • 38

1 Answers1

1

You're likely using CRLF or CR instead of just a line feed for line breaks. Switch to using LF only or normalize your string to it prior to running through preg_match and what you've got will just work.

Community
  • 1
  • 1
user3942918
  • 25,539
  • 11
  • 55
  • 67
  • Thanks. This works on Windows: print (preg_match ('~^stuff$~m', str_replace("\x0d\x0A","\x0A",$p))); though I would like a solution for all platforms... and oddly normaising to PHP_EOL fails. – ChrisJJ Sep 25 '15 at 17:41