I have a string containing this data i would like to retrieve the data "xxxxxxx " enclosed with the youtube bbcode.. how do i fo that? please enlighten me.. thanks
$string = 'haha haha haaha haha haha [youtube]xxxxxxx[/youtube]'; preg_match('/(\[youtube\])(.*?)(\[\/youtube\])/i', $string, $matches); $matches[2] contains what you are looking for
hopefully this works... coded right off my head... // original string contents $string = "haha haha haaha haha haha [youtube]xxxxxxx[/youtube] haha haha haha haha"; // $result will contain "xxxxxxx[/youtube] haha haha haha haha" $result = substr($string, strpos($string, "[youtube]") + 9); // $result will contain "xxxxxxx" $result = substr($result, 0, strpos($result, "[/youtube]")); Code (markup):