Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

regex php auto detect youtube image and regular links using -'php,regex,hyperlink,preg-replace'


regex php auto detect youtube image and regular links  using -'php,regex,hyperlink,preg-replace'

I want to make it so that in my chat-application, links to websites can be clickable and links to YouTube and images automatically gets embedded.

I've made this code in Java for my WebIRC client but now I'm trying to make it in PHP and JavaScript.

I'm not familiar with PHP yet so I don't know that much about using regex there. I wonder if some kind soul could help me with this...

For the YouTube-thingy I tried this without success:

if (preg_match("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#", $message, $m)) {
    $video_id = $m[1];
    $message = preg_replace("#(?<=v=)[a-zA-Z0-9-]+(?=&)|(?<=v\/)[^&\n]+|(?<=v=)[^&\n]+|(?<=youtu.be/)[^&\n]+#","<iframe class='embedded-video' src='http://www.youtube.com/embed/" . $video_id . "' allowfullscreen></iframe>",$message);
}

    

asked Sep 7, 2015 by rajesh
0 votes
10 views



Related Hot Questions



Government Jobs Opening


...