Hi, I'm trying to retrieve the integer value between the <span> tag from a HTML source code.
HTML source code:
<span>
(3861822)
</span>
This is the php code:
<!DOCTYPE html>
<html>
<body>
<?php
//use curl to get html content
function getHTML($url,$timeout)
{
$ch = curl_init($url); // initialize curl with given url
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]); // set useragent
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // write the response to a variable
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // follow redirects if any
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); // max. seconds to execute
curl_setopt($ch, CURLOPT_FAILONERROR, 1); // stop when it encounters an error
return @curl_exec($ch);
}
$html=getHTML("http://www.alibaba.com/Products",10);
preg_match("/<span>(.*)<\/span>/i", $html, $match);
$title = $match[1];
echo $title;
?>
</body>
</html>
Whenever I try to run it, this error will come out: Notice: Undefined offset: 1 in C:\xampp\htdocs\myPHP\index.php on line 19.
How to correct it so that it will display all the integer value within the tag name but without the bracket? Thanks