Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中从2个标记的文本之间获取正则表达式_Php_Regex_Preg Match - Fatal编程技术网

在PHP中从2个标记的文本之间获取正则表达式

在PHP中从2个标记的文本之间获取正则表达式,php,regex,preg-match,Php,Regex,Preg Match,我有一条像绳子一样的线 <li class="video_description"><strong>Description:</strong> hello world, This is test description.</li> 描述:你好,这里是测试描述 我想要这样的字符串,“你好,世界,这是测试描述。”该字符串每次都是动态的 那么,我如何在这里使用preg_match选项呢?在PHP中使用正则表达式解析html不是一个好主意 我建议使用它

我有一条像绳子一样的线

<li class="video_description"><strong>Description:</strong> hello world, This is test description.</li>
  • 描述:你好,这里是测试描述
  • 我想要这样的字符串,“你好,世界,这是测试描述。”该字符串每次都是动态的


    那么,我如何在这里使用preg_match选项呢?

    在PHP中使用正则表达式解析html不是一个好主意


    我建议使用它,因为它简单且适合您的情况

    所有关于使用正则表达式解析html的免责声明,如果您想要正则表达式,您可以使用:

    >\s*\K(?:(?!<).)+(?=</li)
    
    \s*\K(?:(?!\s*
    匹配结束符
    和可选空格
  • \K
    告诉引擎放弃与其返回的最终匹配项相距甚远的匹配项
  • (?:(?!另一种解决方案

    <li.*<\/strong>\s?(.*)<\/li>
    

    如果我在下面加上。preg\u match(“/>\s*\K(?:(?!@UrjitGandhi)嘿,我不确定你想用你的评论说什么,但发布了PHP代码示例以防万一。:)是的,这是正则表达式不适用于你时的选项。
    
    <li.*<\/strong>\s?(.*)<\/li>
    
    $string = '<li class="video_description"><strong>Description:</strong> hello world, This is test description.</li>';
    $pattern = '/<li.*<\/strong>\s?(.*)<\/li>/';
    if(preg_match($pattern, $string)){
      echo "Macth was found";
    }