我是PHP新手,需要获得" url"和"描述"来自以下字符串。
<a href="https://www.youtube.com/watch?v=KhnVcAC5bIM">Official: Desi Kalakaar Full VIDEO Song | Yo Yo Honey Singh | Honey Singh New Songs 2014</a>
任何帮助。
由于
答案 0 :(得分:3)
更好的方法是使用SimpleXMLElement
类:
$str = '<a href="https://www.youtube.com/watch?v=KhnVcAC5bIM">Official: Desi Kalakaar Full VIDEO Song | Yo Yo Honey Singh | Honey Singh New Songs 2014</a>';
$elem = new SimpleXMLElement($str);
$url = $elem->attributes();
$url = $url["href"];
$description = $elem->__toString(); // or just $elem.
echo "URL: " . $url;
echo "<br>";
echo "Description: " . $description;
答案 1 :(得分:1)