Is there a way in which you could produce arrays for each of them, so that it only requires one preg_replace? I'm not asking you specifically to do it, but is there a way?![]()

Is there a way in which you could produce arrays for each of them, so that it only requires one preg_replace? I'm not asking you specifically to do it, but is there a way?![]()
This is our situation and we're happy to be here,
I wouldn't change this place for anything.
PHP Code:<?php
$string = '[b]hay [u]lol[/u][/b]';
$bbcode = array(
'/\[b\](.*?)\[\/b\]/is',
'/\[u\](.*?)\[\/u\]/is'
);
$replace = array(
'<strong>$1</strong>',
'<u>$1</u>'
);
$string = preg_replace( $bbcode, $replace, $string );
echo $string;
?>
@excellent do this:
EDIT: simon beat mePHP Code:$whatever = "[b] bold [/b] [i] italics [/i]";
echo bbcode($whatever);
![]()
Last edited by DUB; 26-09-2008 at 09:57 PM.
;veni vidi vici
;i came, i saw, i ownt
Ah thankyouI know this may sound dumb, but how do you know where to use slashes and all that with the bbcode bit(/\[b\]) etc? Cheers
This is our situation and we're happy to be here,
I wouldn't change this place for anything.
If the character is used in reg ex, then you need to escape it.
this worked for me when changing font, size or color using BB:
PHP Code:$string = preg_replace("(\[font=(.+?)\](.+?)\[\/font\])","<font face=$1>$2</font>",$string);
$string = preg_replace("(\[color=(.+?)\](.+?)\[\/color\])","<font color=$1>$2</font>",$string);
$string = preg_replace("(\[size=(.+?)\](.+?)\[\/size\])","<font size=$1>$2</font>",$string);
Last edited by HotelUser; 27-09-2008 at 02:09 PM.
I'm not crazy, ask my toaster.
Want to hide these adverts? Register an account for free!