Jump to content

Recommended Posts

Hy guys. I'm busting my head with this for whole day. I try to extract the first url that is written in my content (wordpress post).

 

 

 

http://soundcloud.com/seq_dragos-1/survivor-eye-of-the-tiger


[ By Survivor | <a href="http://www.lyrics007.com/Survivor%20Lyrics/Eye%20Of%20The%20Tiger%20Lyrics.html" target="_blank">Lyrics</a> | <a href="http://www.amazon.com/The-Rocky-Story-Soundtrack-Anthology/dp/B00000HZY2/ref=sr_1_1?ie=UTF8&qid=1353265582&sr=8-1&keywords=the+rocky+story" target="_blank">Get the album</a> ]

 

So, I have this URL I want to extract: http://soundcloud.co...ye-of-the-tiger on a first line.

 

 

I tried dozens of solutions. From regex and preg_match to parse_url...

 

At the moment I have this code:

 

unction parseAudio($path){
$parsedUrl = parse_url($path);

if($parsedUrl['host'] == 'soundcloud.com' || $parsedUrl['host'] == 'www.soundcloud.com'){
// for soundcloud
$embedUrl = parse_url($path, PHP_URL_PATH);
echo "http://soundcloud.com$embedUrl";
}
}

 

 

This code kind of does what I want. I get this:

<iframe width="580" height="435" src="http://soundcloud.com/seq_dragos-1/survivor-eye-of-the-tiger____[ By Survivor | <a href="http://www.lyrics007.com/Survivor%20Lyrics/Eye%20Of%20The%20Tiger%20Lyrics.html" target="_blank">Lyrics</a> | <a href="http://www.amazon.com/The-Rocky-Story-Soundtrack-Anthology/dp/B00000HZY2/ref=sr_1_1" frameborder="0" allowfullscreen></iframe> 

 

Problem is that path doesn't stop after URL. It continues on to the text.

 

What can be done with this? Please, if anybody has any idea, share it. Thank you!

Edited by seito86
Link to comment
https://forums.phpfreaks.com/topic/270883-url-extraction-from-page-text-string/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.