0

i have this code

preg_match_all('%(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $asd, $match); 

to find youtube key of urls like

<a href="http://www.youtube.com/watch?v=">http://www.youtube.com/watch?v=ZiJRPREeQ1Q</a> <br /> <a href="http://www.youtube.com/watch?v=GaEZgqxPHLs&feature=related">http://www.youtube.com/watch?v=GaEZgqxPHLs&feature=related</a> 

this work good to find the code ZiJRPREeQ1Q and GaEZgqxPHLs , now i want to replace all the html line with a new code

wanna to use

preg_replace 

to find the whole youtube url

<a href="*">*</a> 

to a new code how can i do that ?

--------------adds--------------

after i get the code of youtube from url by preg_math_all i used this code to extract the codes

foreach($match[1] as $youtube){ // $youtube; // this handle the youtube code $match = ""; // what can i write here relative to $youtube ? $str .= preg_replace($match, 'new code',$content); // $content handle the whole thread that contain the youtube url <a href=*>*</a> } 

the only thing that i need that what's regular expression that i can use to replace youtube code

3
  • 1
    See here and here Commented Dec 29, 2011 at 0:44
  • 1
    If you "wanna to use" preg_replace, then you will have to learn how it works. It's entirely doable, but not suitable to beginners. (If you just wanted some readymade code, the search might turn up something.) Commented Dec 29, 2011 at 0:53
  • i update my post , read it please Commented Dec 29, 2011 at 1:24

1 Answer 1

1
$html = file_get_contents($url); //or curl function $re="<link itemprop=\"embedURL\" href=\"(.+)\">"; preg_match_all("/$re/siU", $html, $matches); $youtube = $matches[1][0]; 

or

$html = file_get_contents($url); //or curl function $re="<link itemprop=\"url\" href=\"(.+)\">"; preg_match_all("/$re/siU", $html, $matches); $youtube = $matches[1][0]; 
Sign up to request clarification or add additional context in comments.

1 Comment

THAT'S will not replace !! i wanna replcae the html code of youtube from <a> to </a> into another code like $new

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.