Array ( [0] => [youtube]http://www.youtube.com/watch?v=eWv8SULLWqg[/youtube] ) [1] => Array ( [0] => http://www.youtube.com/watch?v=eWv8SULLWqg ) ) */ // Then foreach found tag check in which format it is given and generate a Youtube HTML Player object. foreach($matches[1] as $match) { /* $match = http://www.youtube.com/watch?v=eWv8SULLWqg */ if(preg_match('/http:\/\/www\.youtube\.com\/watch\?v=([^\&]{1,})/i', $match, $v_match)) { /* $v_match = Array ( [0] => http://www.youtube.com/watch?v=eWv8SULLWqg [1] => eWv8SULLWqg ) */ $message = str_replace( '[youtube]'.$match.'[/youtube]', /* the found match in the $message */ '', /* replacement html youtube object */ $message); /* the html output buffer */ } elseif(preg_match('/http:\/\/www\.youtube\.com\/v\/([^\&]{1,})\?(.*)/i', $match, $v_match)) { /* $v_match = Array ( [0] => http://www.youtube.com/v/eWv8SULLWqg?fs=1&hl=nl_NL [1] => eWv8SULLWqg [2] => fs=1&hl=nl_NL ) */ $message = str_replace( '[youtube]'.$match.'[/youtube]', /* the found movie in the $message */ '', /* replacement html youtube object */ $message); /* the html output buffer */ } } } return $message; } ?>