1

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

2 Answers 2

3

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Throwing syntax error near $url = $elem->attributes()["href"]; Error = syntax error, unexpected '['
@user3820288 That means you're using an older version of PHP. Try the updated code.
1
.*?\"(.*?)\">(.*?)<\/a>

You can try this.

See demo.

http://regex101.com/r/nC8jC7/1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.