Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.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 li需要正则表达式吗_Php_Regex_Html Lists - Fatal编程技术网

Php li需要正则表达式吗

Php li需要正则表达式吗,php,regex,html-lists,Php,Regex,Html Lists,如何在php中获取li标记之间的字符串?我试过很多php代码,但都不起作用 <li class="release"> <strong>Release info:</strong> <div> How.to.Train.Your.Dragon.2.2014.All.BluRay.Persian </div> <div> How.to.Train.Your.Drag

如何在php中获取
li
标记之间的字符串?我试过很多php代码,但都不起作用

<li class="release">
    <strong>Release info:</strong>
    <div>
        How.to.Train.Your.Dragon.2.2014.All.BluRay.Persian
    </div>
    <div>
        How.to.Train.Your.Dragon.2.2014.1080p.BRRip.x264.DTS-JYK
    </div>
    <div>
        How.to.Train.Your.Dragon.2.2014.720p.BluRay.x264-SPARKS
    </div>
</li>
  • 发布信息: How.to.Train.Your.Dragon.2.2014.All.BluRay.Persian How.to.Train.Your.Dragon.2.2014.1080p.BRRip.x264.DTS-JYK How.to.Train.Your.Dragon.2.2014.720p.BluRay.x264-SPARKS
  • 您可以试试这个

    $myPattern = "/<li class=\"release\">(.*?)<\/li>/s";
    $myText = '<li class="release">*</li>';
    preg_match($myPattern,$myText,$match);
    echo $match[1];
    
    $myPattern=“/
  • (.*?)/s”; $myText='
  • *
  • ; 预匹配($myPattern,$myText,$match); echo$match[1];
    您不需要正则表达式。似乎是(我从T.J.Crowder的评论中获取了URL)

    使用工具解析HTML,例如:DOM库

    这是一个获取所有字符串的解决方案(我假设这些是文本节点的值):

    print\r($strings)输出:

    Array
    (
        [0] => Release info:
        [1] => How.to.Train.Your.Dragon.2.2014.All.BluRay.Persian
        [2] => How.to.Train.Your.Dragon.2.2014.1080p.BRRip.x264.DTS-JYK
        [3] => How.to.Train.Your.Dragon.2.2014.720p.BluRay.x264-SPARKS
    )
    
    强制性链接:
    Array
    (
        [0] => Release info:
        [1] => How.to.Train.Your.Dragon.2.2014.All.BluRay.Persian
        [2] => How.to.Train.Your.Dragon.2.2014.1080p.BRRip.x264.DTS-JYK
        [3] => How.to.Train.Your.Dragon.2.2014.720p.BluRay.x264-SPARKS
    )