1

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) ;

2
  • The array you show can't be the $data array. Easiest but not most elegant way would be to use $array['title']=$array['title'][0]; There may be better ways to do it, but then we need a bit more code. Commented Sep 1, 2010 at 23:07
  • don't works! i've tried a lot of ways but i cant make it work. Commented Sep 1, 2010 at 23:18

2 Answers 2

1

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];
}
Sign up to request clarification or add additional context in comments.

2 Comments

don't works, and also breaks the array: <code> Array ( [type] => yahoo [id] => 613478/2923165 [title] => </code>
it breaks again! any new idea?
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;
}

4 Comments

don't works shows me an empty array, but if delete the [0] part i got: [title] => Array ( [title] => Array ( [0] => EXELENTE TIRO DE ARCO!!
Based on your new edit I see how you're doing it. In that case JoostK's answer above should be correct. It's good practice to declare your variables before using them.
greenbandit: Try removing the ampersand (&) before the $data variable in JoostK's code above.
The ampersand is there because I pass the variable by reference. In PHP it doesn't matter (as far as I know) whether you do it or not, however now I can clearly see that the variable is a reference, not having to look it up in the documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.