0
我有一个小的PHP脚本,我用来获取数据。可能这里有一个正则表达式错误,但我无法解决。PHP正则表达式删除一个字符串
我得到的输出如下所示。如果我尝试$标题[3] [1],我得到的输出输出如下:string(30) "30charstitle"
var_dump($title[3][1]); gives-> string(30) "30charstitle"
var_dump($title[3][2]); gives-> string(50) "50charstitle"
var_dump($title[3][3]); gives-> string(100) "100charstitle"
我想删除该字符串的一部分和双引号从输出,但我被困。基本上我所需要的只是标题本身,不包括双引号和字符串的长度。
function siteConnect($site) {
$ch = curl_init();
$hc = "YahooSeeker-Testing/v3.9 (compatible; Mozilla 4.0; MSIE 5.5; Yahoo! Search - Web Search)";
curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
curl_setopt($ch, CURLOPT_URL, $site);
curl_setopt($ch, CURLOPT_USERAGENT, $hc);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$site = curl_exec($ch);
curl_close($ch);
// preg_match
preg_match_all('@><a itemprop="url" href="http://www.example.com/id/(.*?)/(.*?).html&path=(.*?)"><span itemprop="name">(.*?)</span></a>@',$site,$title);
$title[3][1] = strip_tags($title[3][1]);
$title[3][1] = preg_replace('~.*?>~', '', $title[3][1]);
var_dump($title[3][1]);
}
$enter = siteConnect('http://www.example.com/index.php?route=product/category&path=5_6&page=1');
只需用'echo'替换'var_dump' – anubhava 2015-02-11 17:46:52
我感到难过。谢谢。问题解决了。 – salep 2015-02-11 17:48:00
@salep:不要伤心:-) – AbraCadaver 2015-02-11 18:09:04