Reputation: 225
I am new to the PHP, need to get "url" and "description" from following string.
<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>
Any help.
Thanks
Upvotes: 1
Views: 94
Reputation: 39458
A better way to go about it would be to use the SimpleXMLElement
class:
$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;
Upvotes: 3
Reputation: 67968
.*?\"(.*?)\">(.*?)<\/a>
You can try this.
See demo.
http://regex101.com/r/nC8jC7/1
Upvotes: 1