0

hi guys,

i have a rege code that looks to see if a block of text has a link.
i have modded it to show the link as an image if it exists (badly i know this method isnt very good)

what i need to do is check if the text contains a link, image,or video (youtube/dailymotion etc) and then display the right output

heres what i have

<?php 
        $convertlinkmsg = $message->message;
        $convertlinkmsg  = preg_replace( '/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i', '<a target="_blank" class="imgsoc "  href="\0"><img src="\0" alt="\4"/></a>', $convertlinkmsg); 

        echo $convertlinkmsg ; ?> 

any ideas?
thanks

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by diafol
0

How do you want to replace images and videos? With the actual image or a video iframe?
Perhaps an easier way would be to search for .png, .jp(e)g, .gif, .svg files and replace those with an img tag BUT some online images are sometimes generated via php files (e.g. image.php?id=3456), so it's not always as straightforward.

For the videos, those links may have 'youtu(.)be' etc in them, but equally other non-youtube urls may have a 'youtube' folder - so you'll have to be very specific.

I assume you'll need a different regex for each video site.

Instead of listing loads of separate preg_replace() you can use arrays for the 'search' and 'replace' parameters.

JS idea: http://stackoverflow.com/questions/7168987/how-to-convert-a-youtube-video-url-to-the-iframe-embed-code-using-jquery-on-pag

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.