我想把下面代码里的/MusicData/play/201512/5684f44201b44.mp3这个给匹配出来
<code> <div class="commentRoll hide"> oooovc: <span style="color:#01aebf">终于有更新的曲子了!等得花都谢了</span> DJHarlem: <span style="color:#01aebf">不错的曲子 值得拥有~</span> NONGZEMING: <span style="color:#01aebf">不错!我喜欢!</span> NONGZEMING: <span style="color:#01aebf">不错!我喜欢!</span> xx602285388: <span style="color:#01aebf">套曲不错~~~</span> 155774a:<a>本2文来*源gao($daima.com搞@代@#码(网</a><strong>搞gaodaima代码</strong> <span style="color:#01aebf">感谢分享好音乐</span> 1098263279: <span style="color:#01aebf">非常不错的曲子</span> 376663234: <span style="color:#01aebf">霸气 不错的套曲 支持</span> 936431866dj: <span style="color:#01aebf">不错,赞一个</span> a670529347: <span style="color:#01aebf">嗨嗨嗨嗨嗨~</span> </code>
回复内容:
我想把下面代码里的/MusicData/play/201512/5684f44201b44.mp3这个给匹配出来
<code> <div class="commentRoll hide"> oooovc: <span style="color:#01aebf">终于有更新的曲子了!等得花都谢了</span> DJHarlem: <span style="color:#01aebf">不错的曲子 值得拥有~</span> NONGZEMING: <span style="color:#01aebf">不错!我喜欢!</span> NONGZEMING: <span style="color:#01aebf">不错!我喜欢!</span> xx602285388: <span style="color:#01aebf">套曲不错~~~</span> 155774a: <span style="color:#01aebf">感谢分享好音乐</span> 1098263279: <span style="color:#01aebf">非常不错的曲子</span> 376663234: <span style="color:#01aebf">霸气 不错的套曲 支持</span> 936431866dj: <span style="color:#01aebf">不错,赞一个</span> a670529347: <span style="color:#01aebf">嗨嗨嗨嗨嗨~</span> </code>
<body>
<code><?php$a = <<<EOF <div class="commentRoll hide"> oooovc: <span style="color:#01aebf">终于有更新的曲子了!等得花都谢了</span> DJHarlem: <span style="color:#01aebf">不错的曲子 值得拥有~</span> NONGZEMING: <span style="color:#01aebf">不错!我喜欢!</span> NONGZEMING: <span style="color:#01aebf">不错!我喜欢!</span> xx602285388: <span style="color:#01aebf">套曲不错~~~</span> 155774a: <span style="color:#01aebf">感谢分享好音乐</span> 1098263279: <span style="color:#01aebf">非常不错的曲子</span> 376663234: <span style="color:#01aebf">霸气 不错的套曲 支持</span> 936431866dj: <span style="color:#01aebf">不错,赞一个</span> a670529347: <span style="color:#01aebf">嗨嗨嗨嗨嗨~</span>EOF;preg_match('/ url="(.+?)"><\/a>/', $a, $b);var_dump($b);</code>
用PHP的XML的XPath最好了
XPath语法参加这里XPath语法
这里有一个小例子
<code class="PHP"><?php$xml = simplexml_load_file("test.xml");$result = $xml->xpath("//a[@class='play-item' and @url]");print_r($result);?></code>
我们可以找到所有a标签class属性为’play-item’且有url属性的元素,然后就是对PHP中SimpleXMLElement类的操作了