preg_match() doesn't work on host
<?php
$pattern = \"/BEGIN_OS ([0-9]+)\n((.|\n)+)END_OS/\"; // specialised pattern for OS section
preg_match($pattern, $logfile, $os_section); // find section
?>
I'm using that code to match a section of a file that looks like this:
BEGIN_OS 5
Unknown 90
linux 3787
win98 15
winxp 94
win2000 24
END_OS
The problem is, there is no problem. It works perfectly on my localhost. I've even built the rest of the script and page. However, when I run it on my remote host account, it doesn't work. No error messages or anything -- nothing is returned; a blank page or no page at all. I cannot for the life of me figure out why.
I know it's connected to that bit of code because I commented out those lines and things seem to load.
I looked in the PHP error logs and found nothing.
I tried testing preg_match() in other conditions and that works...
I'm running Apache 2.0.50/PHP 5.0.0 on my box, host runs Apache 1.3.31/PHP 4.3.8. I searched for documentation on differences in regex handling for these versions without luck.
Is my regex bad? Anybody experienced this before? Any ideas?
:confused:
Abhishek Reddy posted this at 13:46 — 18th July 2004.
He has: 3,348 posts
Joined: Jul 2001
Solved.
I used:
<?php
$pattern = \"/BEGIN_OS ([0-9]+)\n(.+)END_OS/s\"; // specialised pattern for OS section
?>
The /s modifier included newlines for . so I didn't need (.|\n), which seemed to be the problem part anyhow. I'd still like to know why it worked on my server...
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.