I am trying to get the variable $matches to be usable outside of this function. So I can use echo $matches[0][0]; or $matches[0][1]; after the function gets used in my document. So far I haven't been able to use the matches variable outside of the function at all.
function curlLink($url, $regex)
{
include ('lib/dBug.php');
require_once('lib/curl_http_client.php');
$curl = &new Curl_HTTP_Client();
//$useragent = "Googlebot/2.1 (+http://www.google.com/bot.html)";
$useragent = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0";
$curl->set_user_agent($useragent);
ini_set('max_execution_time','0');
$x=0;
$matches = array();
while (sizeof($matches) == 0 && $x < 15) {
$html_data = $curl->fetch_url($url);
preg_match_all($regex, $html_data, $matches);
$x++;
array_shift($matches);
}
if (empty($matches[0][0])) {
echo '<img src=\"/img/bigbrokenlink.png\" /><br /><br />
<b>Sorry, no results from your search!</b><br />';
}
if (!empty($matches[0][0])) {
//return $matches; //This doesn't seem to return a usable variable...
$dBug = new dBug ($matches);
}
}