Whats the problem with this preg_match script?
Why does this code not give me any results?
if(preg_match('#referer\.php\?url=(.*?)#s',$result,$array2)) {
echo $array2[1];
}
The thing开发者_JS百科 is, if I change echo $array2[1]
to echo "test";
it will show me test
. So the problem doesnt seem to be the preg_match
algorithm, does it? What could be the problem?
I want to have the url, which is written after the url=
, for example referer.php?url=http://www.example.com
should give http://www.example.com
as result in the $array2
.
Thanks for your help!
try changing it this way:
if(preg_match('#referer\.php\?url=(.*)$#s',$result,$array2))
so print_r($array2)
will output:
Array
(
[0] => referer.php?url=http://www.example.com
[1] => http://www.example.com
)
that is the result you want. Hope it helps!
if your input is: <td align="center" width="90%"><b><a target="_blank" href="/referer.php?url=http://www.example.com?somethin=1234">Go to this homepage</a></b>
and you want http://www.example.com?somethin=1234
,
Your regex would look like this:
/referer\.php\?url=([^"]*)
That would make your php look like this:
if(preg_match('#/referer\.php\?url=([^"]*)#',$result,$array2)){
print_r($array2);
}
精彩评论