Guest Posted November 18, 2012 Share Posted November 18, 2012 (edited) 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 November 18, 2012 by seito86 Quote Link to comment https://forums.phpfreaks.com/topic/270883-url-extraction-from-page-text-string/ Share on other sites More sharing options...
AyKay47 Posted November 19, 2012 Share Posted November 19, 2012 The function you wrote really doesn't do anything helpful to your situation. What RegExp have you tried so far? Quote Link to comment https://forums.phpfreaks.com/topic/270883-url-extraction-from-page-text-string/#findComment-1393542 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.