View Full Version : preg_match problems...
SessTehKing
04-06-2007, 07:00 PM
<?php
$sess = file_get_contents("http://www.test.com/")
if(preg_match("/Test/i", $sess)){
echo "Found.";
} else {
echo "Not found.";
}
?>
Is it because I can't file_get_contents from outside websites or something? Or is there something else wrong...
mburt
04-06-2007, 07:37 PM
Is it because I can't file_get_contents from outside websites or something?
I'd say it is...
An error would be outputted if it was. Is there a php error?
SessTehKing
04-06-2007, 11:20 PM
No. That's why I'm skeptical. It simply says "Not found" no matter what.
boogyman
04-07-2007, 01:39 AM
<?php
$sess = file_get_contents("http://www.test.com/")
if(preg_match("/Test/i", $sess)){
echo "Found.";
} else {
echo "Not found.";
}
?>
is looking for "Test" case-insensitive inside the actual contents of the url, not the url itself. A good way to find out what the string that is being passed I suggest that you print it out after, which is a good debugging tool.
echo $sess
mburt
04-07-2007, 01:55 AM
No. That's why I'm skeptical. It simply says "Not found" no matter what.
There's no error, it's just that test wasn't found.
You may want to try a global regex though:
/Test/gi
SessTehKing
04-07-2007, 02:11 AM
Well "test" wasn't what I used, what I used WAS found in the contents.
And, I tried that in a link...it linked to the page the PHP was located on.
boogyman
04-07-2007, 03:37 PM
Well "test" wasn't what I used, what I used WAS found in the contents.
but did you print out the contents to of where-ever you sent it to, because for some reason its not finding it.
<?php
$sess = file_get_contents("http://www.test.com/")
echo $sess;
if(preg_match("/Test/i", $sess)){
echo "Found.";
} else {
echo "Not found.";
}
?>
do that to find out what is actually being passed then you will know where the problem resides
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.