我试图在下面的字符串中找到http://www.facebook.com$content
,但它没有返回任何内容。请指导。谢谢。
<?php
$content = file_get_contents('http://graph.facebook.com/4');
$url = 'http://www.facebook.com';
$pos = strpos($content, $url); //find position of url in string
echo $pos;
我试图在下面的字符串中找到http://www.facebook.com$content
,但它没有返回任何内容。请指导。谢谢。
<?php
$content = file_get_contents('http://graph.facebook.com/4');
$url = 'http://www.facebook.com';
$pos = strpos($content, $url); //find position of url in string
echo $pos;
内容来自http://graph.facebook.com/4
编码字符串。在此字符串中,斜杠被屏蔽。如果你使用var_dump($contents)
你会看到:
"link":"http:\/\/www.facebook.com\/zuck"
肯定会strpos
回来false
,因为http://www.facebook.com
不存在于$contents
。您可以使用json_decode($content)
来检查什么是link
价值。
首先,在使用 strpos() 时,您需要使用类型检查返回值,因为它可以返回 0(当字符串在 0 位置建立时)或 false(当字符串未建立时)所以第二种情况是你的。var_dump()
改为检查使用echo