Jump to content

Warning: preg_replace() [function.preg-replace]: No ending delimiter '/'


TeddyKiller

Recommended Posts

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);

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.

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 (.*)? ?

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 .*.

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.