Remove quotes from preg_replace



this is for php bb code stuff

by defualt we have this set up:
[box="Title...:"]Text orCode...[/box]
as you can see [box=""] we use quotes

when i run preg_replace the quotes in box="" remain so
we get "Title...:"

what can i add to my syntax so that preg_replace only replaces every thing except Title...:

instead of "Title...:" i want Title...:
"<blockquote><b>\\1</b>\n<div class=\"box\">\\2</div>\n</blockquote>",
'[box="Title...:"]Text orCode...[/box]');

i tried all kinds of things i am just not good at php syntax. thanks for your time i hope you can help me ;-)
Just use \" to escape the quote, like so:

$string = '[box="Title...:"]Text orCode...[/box]'; // or wherever you get that data
$string = preg_replace("#\[box=\"(.*?)\"](.*?)\[box]#is",
"<blockquote><b>\\1</b>\n<div class=\"box\">\\2</div>\n</blockquote>", $string);
// note that it should be one line but word-wrapping is weird here...

... man i swear i tryed that and it wouldnt work lol :( o well thanks ;-) it works now... was so easy too lol thank thanks thanks ;-)

$string = '[box="Title...:"]Text orCode...[/box]';
$string = preg_replace("#\[box=\"(.+?)\"](.+?)\[/box\]#is", "<blockquote><b>\\1</b>\n<div class=\"box\">\\2</div>\n</blockquote>", $string);
echo $string;

oh ok i see what you did wrong [box] ending is open should be [/box\]
dam ok check this out for some reason i get wird bug when i use a form.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>untitled doc</title>
$string = $_POST['string'];
$string1 = preg_replace('#\[box=(.+?)\](.+?)\[/box\]#is', '<blockquote><b>\\1</b><div class="box">\\2</div></blockquote>', $string);
echo $string1;
<form action="index.php" method="post" enctype="application/x-www-form-urlencoded" target="_self">
<textarea name="string" cols="100" rows="10" wrap="virtual"></textarea>
<input name="" type="submit" value="Submit" />

it out puts like this:
Text orCode...

it should be like this
Text orCode...

if you try the above php html code, this is what the bbcode is:
[box="Title...:"]Text orCode...[/box]
o well i just did a cheap hack but i guess it works ;/

have to add this to end of code:
$string = str_replace('<blockquote><b>\"', '<blockquote><b>', $string);
$string = str_replace("\"</b>\n<div class=\"box\">", "</b>\n<div class=\"box\">", $string);
Replace line 10 of your code with this and try again:

$string = stripslashes($_POST['string']);

thanks but i choose to do it like this.

$string = str_replace('<blockquote><b>\"', '<blockquote><b>', $string);//remove left qoute
$string = str_replace("\"</b>\n<div class=\"box\">", "</b>\n<div class=\"box\">", $string);//remove right qoute

Because if for some reason some one needs to type \ in there text, stripslashes will remove it. So not a good idea in this case :oops:.
If someone types \ in their text, it's most likely to be escaped as \\.

When a form is submitted, values are modified (slashes added) and so you should remove them when you use the data...