Regular expressions matching multi-lines
Posted: Sun Sep 12, 2004 12:26 pm
feyd | Please use
I want to match line1, but it doesn't find it even though I've used the /m modifier. I thought this allowed strings to apply to lines.
Is this because I am using Windows and that o/s uses \r\n for line breaks?
feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
Hello, I have a text file with two lines.Code: Select all
line1
line2Is this because I am using Windows and that o/s uses \r\n for line breaks?
Code: Select all
$filename = "file.txt";
$fp = fopen($filename, "r") or die("Cannot open file");
$str = fread($fp, filesize($filename));
$pattern = "/line1$/m";
if(preg_match($pattern, $str, $matches)) {
print "matched: ";
for($i=0; $i<count($matches); $i++) {
print "{$matches[$i]}";
}
}
else {
print "no match";
}feyd | Please use
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]