TeddyKiller Posted May 2, 2010 Share Posted May 2, 2010 Warning: preg_replace() [function.preg-replace]: No ending delimiter '/' found in /home/jeanie/public_html/design/inc/functions.php on line 274 Line 274 is the str_replace. Whats wrong? I'm trying to convert html to bbcode. Thanks $bbcode = array( //Bold '[b]$1[/b]', //Italic '[i]$1[/i]', //Underline '[u]$1[/u]', //Font Family '[font=$1]$2[/font]', //Colors '[c=$1]$2[/c]', //Code presentation '[ code]$1[ /code]' ); $htmlcode = array( //Bold '/\<strong\>(.*?)\<\/strong\>/is', //Italic '/\<em\>(.*?)\<\/em\>/is', //Underline '/\<u\>(.*?)\<\/u\>/is', //Font Family '/\<span style=\"font-family: (.*?);\"\>(.*?)\<\/span\>', //Colors '/\<span style=\"color: (.*?);\">(.*?)\<\/span\>', //Code presentation '/\<pre class=\"code\"\>(.*?)\<\/pre\>/is' ); $str = preg_replace($htmlcode, $bbcode, $str); Quote Link to comment https://forums.phpfreaks.com/topic/200454-warning-preg_replace-functionpreg-replace-no-ending-delimiter/ Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Author Share Posted May 2, 2010 Okay. managed to sort that out, was missing a couple "/is" However.. the string returned, doesn't display the bbcode. It's just normal text. Any help? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/200454-warning-preg_replace-functionpreg-replace-no-ending-delimiter/#findComment-1051907 Share on other sites More sharing options...
khr2003 Posted May 2, 2010 Share Posted May 2, 2010 change this line: $str = preg_replace($htmlcode, $bbcode, $str); to this: $str = preg_replace($bbcode, $htmlcode, $str); You need to take the bbcode and convert it into html and not otherwise. Quote Link to comment https://forums.phpfreaks.com/topic/200454-warning-preg_replace-functionpreg-replace-no-ending-delimiter/#findComment-1051944 Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Author Share Posted May 2, 2010 No, its like that to begin with. As I mentioned I'm trying to convert html to bbcode. I'm getting the data from the database as HTML, and now I want to convert it back to BBCode so it can be editted inside a textbox like that. Quote Link to comment https://forums.phpfreaks.com/topic/200454-warning-preg_replace-functionpreg-replace-no-ending-delimiter/#findComment-1051963 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 You really should use (.*?) carefully. Surely you can use something other than that. It's just too vague. Change it to (.*)? I'm not saying that is any better lol. Quote Link to comment https://forums.phpfreaks.com/topic/200454-warning-preg_replace-functionpreg-replace-no-ending-delimiter/#findComment-1051965 Share on other sites More sharing options...
newbtophp Posted May 2, 2010 Share Posted May 2, 2010 You really should use (.*?) carefully. Surely you can use something other than that. It's just too vague. Change it to (.*)? I'm not saying that is any better lol. Whats the difference between (.*?) and (.*)? ? Quote Link to comment https://forums.phpfreaks.com/topic/200454-warning-preg_replace-functionpreg-replace-no-ending-delimiter/#findComment-1051974 Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Author Share Posted May 2, 2010 You really should use (.*?) carefully. Surely you can use something other than that. It's just too vague. Change it to (.*)? I'm not saying that is any better lol. Whats the difference between (.*?) and (.*)? ? I second that, although that wasn't the problem. I had a strip_tags and htmlentities in. I was playing games and suddenly my brain woke. I thought.. htmlentities is the problem. It wasn't the problem. I saw above it.. strip_tags, I tried removing it and it works. So.. what is the difference between (.*?) and (.*)? ? Quote Link to comment https://forums.phpfreaks.com/topic/200454-warning-preg_replace-functionpreg-replace-no-ending-delimiter/#findComment-1052037 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 I didn't think that was the issue. I was denoting that there is a difference between (.*?) and (.*)? and people usually blindly mis-use them because as evident, you think they're the same thing. So write better regexp and don't rely on .*. Quote Link to comment https://forums.phpfreaks.com/topic/200454-warning-preg_replace-functionpreg-replace-no-ending-delimiter/#findComment-1052040 Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Author Share Posted May 2, 2010 I didn't think that was the issue. I was denoting that there is a difference between (.*?) and (.*)? and people usually blindly mis-use them because as evident, you think they're the same thing. So write better regexp and don't rely on .*. Hmm.. both give the same result. What is the difference if you don't mind answering the question Quote Link to comment https://forums.phpfreaks.com/topic/200454-warning-preg_replace-functionpreg-replace-no-ending-delimiter/#findComment-1052044 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 Find out for yourself. Match everything between [one] and [/one] $str = 'test [one]test[/one] test [one] test test [/one] test'; Quote Link to comment https://forums.phpfreaks.com/topic/200454-warning-preg_replace-functionpreg-replace-no-ending-delimiter/#findComment-1052051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.