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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.