std 类对象值存储在变量中,以便在循环中进一步处理


std class object values storing in a variable for further processing in loop

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,标题作为键并将它们存储在数据库中。

foreach($sr as $sr1)
{
$url= $sr1->url;
...

给出:注意:试图获取非对象的属性搜索了许多页面,回显$sr 1->网址;显示正确答案,但当尝试保存在给定相同错误的变量中时。

$sr是你上面倾倒的对象,还是一个对象数组,其中一个是你转储的对象?如果转储$sr,那么你的foreach((循环是没有意义的,你只需要$sr->url