开发者

problem accessing to a variable in object

Edit: this is part of main function to call the grab function:

  $video['type']          = $videoProvider;
  $video['id']    开发者_开发知识库      = $videoIds;
  $video['title']          = $this->grab_title_from_curl($data);

I have this little function to parse title from html via curl, it works.

  private function grab_title_from_curl ($pull){
    preg_match("/<meta name=\"title\" content=\"(.*?)\"/", $pull,$data) ;
    return $data;
  }

and shows me this:

Array
(
    [type] => yahoo
    [id] => 613478/2923165
    [title] => Array
        (
            [0] =>  EXELENTE TIRO DE ARCO!!
        )
)

I need to [title] directly gets the value of [0] in the array. like: [title] => EXELENTE TIRO DE ARCO!!

second edit:

for some reason the code breaks when i use JoostK's code: pastie.org

sorry for my bad english!

SOLVED: instead of preg_match("/?)\"/", $pull,$data); preg_match('/?)\"/', $pull,$data) ;


Based on your edit, this should work:

private function grab_title_from_curl ($pull){
    $data = array();
    preg_match("/<meta name=\"title\" content=\"(.*?)\"/", $pull, &$data);
    return $data[0];
}


Use a temporary variable to hold the matches:

private function grab_title_from_curl ($pull){
    $matches = array();
    preg_match("/<meta name=\"title\" content=\"(.*?)\"/", $pull, $matches) ;
    $data['title'] = $matches[0];
    return $data;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜