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

Regex get text between the html tags - PHP

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();
}

我在使用 Regex 时遇到一点问题,我只想从 html 标签(包括标签)之间的所有内容中获取文本,然后用这些结果创建一个数组,但是,我'我无法将结果保存到数组中。

基本上,我需要以下 return:

Array(
     [0] => <div>
     [1] => </div>
     [2] => <a href="test/test.com">
     [3] => </a>
)

试试这个

<?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);
}