我试图让变量$匹配在此函数之外使用。所以我可以使用echo $ matches [0] [0];或$匹配[0] [1];该函数在我的文档中使用后。到目前为止,我还没有能够在函数外部使用matches变量。
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);
}
}
从函数返回并使用它? – tfrascaroli 2014-09-28 20:38:05
define“似乎没有返回一个可用的变量” – raina77ow 2014-09-28 20:38:56
你是什么意思“这似乎没有返回一个可用的变量......” – Steve 2014-09-28 20:39:07