Reducing execution time of an HTML parsing script
There's a few things you can do to improve here:


Use curl instead of get_file_contents, it speeds the document retrieval up so much.
The following could be converted to a ternary statement:



if (count($var1) &gt;= 2) {
    $var1 = implode("%20",$var1);
} else {
    $var1 = implode("%",$var1);
}



Notice that the condition is reversed:

$var1 = implode('%' + (!count($var1) &gt;= 2 ?: "20"), $var1);



You shouldn't be joining strings like this: "\""."$var1"."\"":


Do this instead: "\"{$var1}\"" (see that the variable is wrapped in curly braces)


Don't array_push, use the $array[] notation instead.

$return_array[] = $text1;
$return_array[] = $text2;