繁体   English   中英

PHP正则表达式删除字符串

[英]PHP Regular expression to delete a string

我有一个小的PHP脚本,用于获取数据。 这里可能存在正则表达式错误,但我无法解决。

我得到的输出如下所示。 如果我尝试$ title [3] [1], string(30) "30charstitle"得到以下输出: 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');

替换为:

var_dump($title[3][1]);

那:

print($title[3][1]);

要么:

echo $title[3][1];

对于多阵列更好:

print_r($title);

您只想找到合适的地址吗? 如果我明白你的追求。

那么,也许是类似。*“(。*)”。*的东西吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM