Get url from string


/ Published in: PHP
Save to your folder(s)

need to get the url from a youtube/vimeo embedded code without the querystring's


Copy this code and paste it in your HTML
  1. $str = '<iframe width="560" height="315" src="http://www.youtube.com/embed/GHcUkc4tshA?rel=0" frameborder="0" allowfullscreen></iframe>';
  2. $findme = 'http://';
  3. $nextFind = '?';
  4. $next2Find = '"';
  5. $posHttp = strpos($str, $findme);
  6. $pos1 = strpos($str, $nextFind, $posHttp);
  7. $pos2 = strpos($str, $next2Find, $posHttp);
  8.  
  9. if($pos1 < $pos2 && $pos1 != -1) {
  10. echo substr($str, $posHttp, $pos1-$posHttp);
  11. }else {
  12. echo substr($str, $posHttp, $pos2-$posHttp);
  13. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.