views:

38

answers:

2
A: 

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;
}
Rob Olmos
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!!
greenbandit
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.
Rob Olmos
the code breaks! everytime!
greenbandit
Rob Olmos
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.
JoostK
+1  A: 

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