I want to make sure that in my chat application links to sites can be clicked and links to YouTube, and images are automatically inserted.
I made this code in Java for my WebIRC client, but now I'm trying to do it in PHP and JavaScript.
I am not familiar with PHP yet, so I donβt know how much to use regex. I wonder if any soul can 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); }
source share