check string for youtube link or image
<p>I have a small piece of code that checks a string for a url and adds the &lt; a href> tag to create a link. I also have it check the string for a youtube link and then add rel="youtube" to the &lt; a> tag. </p>

<p>How can I get the code to only add rel to the youtube links?</p>

<p>How can I get it to add a different rel to any type of image link?</p>

<pre><code>$text = "http://site.com a site www.anothersite.com/ http://www.youtube.com/watch?v=UyxqmghxS6M here is another site";

$linkstring = preg_replace( '/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i', '&lt;a href="\0"&gt;\4&lt;/a&gt;', $text ); 
if(preg_match('/http:\/\/www\.youtube\.com\/watch\?v=[^&amp;]+/', $linkstring, $vresult)) {
    $linkstring = preg_replace( '/(http|ftp)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i', '&lt;a rel="youtube" href="\0"&gt;\4&lt;/a&gt;', $text ); 
          $type= 'youtube';
          }
else {
$type = 'none';
}
echo $text;
echo $linkstring, "&lt;br /&gt;";
echo $type, "&lt;br /&gt;";
</code></pre>
