|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-09-04 19:43 UTC] nino at recgr dot com
Description:
------------
When you put file_get_contents('some_file.ext') as a second argument in preg_match() it doesn't work. However, when you put that file_get_contents() into a variable, and THEN you insert that variable as a second argument, it works. At least at remote files (I'm not sure about local files) and when there is a third argument too.
Reproduce code:
---------------
preg_match("<pattern>", file_get_contents('http://www.example.com'), $found);
Expected result:
----------------
Found matches in array $found.
Actual result:
--------------
Nothing.
However, when put your script thus:
$url = file_get_contents('http://www.example.com');
preg_match("<pattern>", $url, $found);
then it works.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 03:00:01 2025 UTC |
WORKING VERSION: function grabData($page) { $lookHere = file_get_contents($page); preg_match("<pattern>", $lookHere, $found); } NON-WORKING VERSION: function grabData($page) { preg_match("<pattern>", file_get_contents($page), $found); } With that previous, non-working example, $found is an empty array, while the first example works.Private reproduce code? Works perfectly fine here. <?php preg_match("/(.*)/", file_get_contents('http://www.google.com'), $found); var_dump($found); ?> array(2) { [0]=> string(118) "<html><head><meta http-equiv="content-type" content="text/html; charset=windows-1251"><title>Google</title><style><!--" [1]=> string(118) "<html><head><meta http-equiv="content-type" content="text/html; charset=windows-1251"><title>Google</title><style><!--" } Marked as bogus, since we don't have any way to reproduce it.