Posted By

fetz on 01/31/12


Tagged

url embed


Versions (?)

Get url from string


 / Published in: PHP
 

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

  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  

You need to login to post a comment.