正则表达式在html标签之间获取文本 - PHP

时间:2018-01-07 04:43:55

标签: php html regex tags preg-match

var options = {
            type: "basic",
            title: "Extention Title",
            message: 'Extention Message",
            iconUrl: "images/icon_86.png" // My Case:Error in iconUrl
        };

我对Regex有一点问题,我只想从html标签(包括标签)之间的所有内容中获取文本并创建包含这些结果的数组,但是,我无法将结果保存到数组中。

基本上,我需要以下回报:

function teste(){
    $string = '<div>Hello, i am João</div><a href="test/test.com">testttttttttttt</a>';
    $matches = array();

    preg_match('/<[^>]*>/', $string, $matches, PREG_OFFSET_CAPTURE);
    print_r($matches);exit();
}

1 个答案:

答案 0 :(得分:1)

试试这个

<?php function teste(){
    $string = '<div>Hello, i am João</div><a 
   href="test/test.com">testttttttttttt</a>';
   $matches = array();

    preg_match_all('/<[^>]*>/', $string, $matches);
    echo '<pre>';
    print_r($matches);
}