PHP Code:
<?php



function BBCode ($post_raw) {

$search = array(

        
'@\[(?i)b\](.*?)\[/(?i)b\]@si',

        
'@\[(?i)i\](.*?)\[/(?i)i\]@si',

        
'@\[(?i)u\](.*?)\[/(?i)u\]@si',

        
'%(@post#)(\d+)%',

        
'@\[(?i)img\](.*?)\[/(?i)img\]@si',

        
'@(?:https://)?(?:http://)?(?:www\.)?(?:youtube\.com/(?:v/|watch\?v=)|youtu\.be/)([\w-]+)(?:\S+)?@si',

        
'@\[(?i)url\](.*?)\[/(?i)url\]@si'

);

$replace = array(

        
'<b>\\1</b>',

        
'<i>\\1</i>',

        
'<u>\\1</u>',

        
'<a href="#$2">$1$2</a>',

        
'<img src="\\1" onclick="imagesize(this)" alt="Img broke or loading" style="height:200px" />',

        
'<embed width="275" height="225" src="https://www.youtube.com/v/$1" type="application/x-shockwave-flash" wmode="direct" allowfullscreen="true" />',

        
'<a href="\\1" target="_blank">\\1</a>'

);

return 
preg_replace($search$replace$string);

}



?>

How would I make it auto create URL's while it still auto embeds youtube videos?

it requires a url tag currently, I'd like it to (if http:// exists) just auto create the URL, without messing up a youtube video if it's in the same post.

probably other stuff is not as good as it can be if anyone knows how to fix whatever (all works fine now, just want URL's to auto embed like youtubes do)