stdClass Object
(
[GsearchResultClass] => GwebSearch
[unescapedUrl] => http://www.imdb.com/title/tt1536048/
[url] => http://www.imdb.com/title/tt1536048/
[visibleUrl] => www.imdb.com
[cacheUrl] => http://www.google.com/search?q=cache:WoifaIygcOQJ:www.imdb.com
[title] => W.E. (2011) - IMDb
[titleNoFormatting] => W.E. (2011) - IMDb
[content] => The affair between King Edward VIII and American divorcée Wallis Simpson, and
a contemporary romance between a married woman and a Russian security ...
)
将这些对象作为密钥接收,现在尝试将url,title作为密钥并将其存储在数据库中。
foreach($sr as $sr1)
{
$url= $sr1->url;
...
给出:注意:尝试获取非对象的属性 搜了很多页, echo $ sr1-> url; 显示正确的答案但是在尝试保存给定相同错误的变量时。
答案 0 :(得分:0)
$sr
是您上面转储的对象,还是一个对象数组,其中一个是您转储的对象?如果转储 IS $ sr,那么你的foreach()循环是没有意义的,你只需要$sr->url
。