Jump to content

Problem with BB code regex


MartinGr

Recommended Posts

Hi,

I have been using the following regex for BB code on several occasions and that’s the first time to run into problem like this. The problem occurred when I added code tag for code highlight using Geshi. The code I’m using is:

 while (preg_match('#\[(.+)(?:=(.*?))?\](.*?)\[\/\1\]#s',$text)) {
    $text = preg_replace_callback('#\[(.+)(?:=(.*?))?\](.*?)\[\/\1\]#s', 'parse_bb_callback', $text);
  } 

The problem is, that on some occasions it fails to find any tags in string even though they are there. I can’t figure out why. I’ll just copy 2 random posts contents from my forum to demonstrate the matter.

Following post gets parsed perfectly:

 [quote=Autor]Quote content[/quote]
Text content
[code=HTML]<div class="art-post">
<div class="art-post-body">
<div class="art-post-inner">
<div class="art-postmetadataheader">
<h2 class="art-postheader"><img src="/templates/vannisalong1/images/postheadericon.png" alt="postheadericon" width="30" height="30" />

Valamud
</h2>
</div>
<div class="art-postcontent">
<!-- article-content -->
<div class="art-article"><p> </p>
<table align="center" border="0">
<tbody>
<tr>
<td><a target="_blank" href="http://www.ravak.ee/?page=ppu"><img height="190" width="220" src="/images/stories/Ravak/ravakvalamu.jpg" alt="ravakvalamu" /></a></td>
<td><a target="_blank" href="http://paavannid.ee/index.php?sub=valamud"><img height="190" width="220" src="/images/stories/Paa/paavalamu.jpg" alt="paavalamu" /></a></td>
</tr>
<tr>
<td>          <a target="_blank" href="http://www.ravak.ee/?page=ppu">RAVAK valamud</a></td>

<td>            <a target="_blank" href="http://paavannid.ee/index.php?sub=valamud">PAA valamud</a></td>
</tr>
</tbody>
</table>

More text

border:1px solid #4A691C;

More text [/code]

 

However, if I add

[code=CSS].art-post {
margin:5px;
}
.art-post {
margin:0 auto;
min-height:1px;
min-width:1px;
position:relative;
z-index:0;
}

.art-post-body {
padding:15px;
position:relative;
z-index:1;
}

.art-postmetadataheader {
background-color:#D3E9C3;
padding:1px;
}

.art-postheader {
color:#1C2D11;
font-size:26px;
margin:0.2em 0;
padding:0;
}

.art-postcontent {
letter-spacing:1px;
line-height:125%;
margin-left:5px;
margin-right:5px;
text-align:justify;
}

[/code]

It won’t render a single tag and 'parse_bb_callback won’t execute even once. Thereby I conclude that the problem must be in the regular expression, but what exactly?

Nested quotes work, several code tags in one post also work in other posts. What could be causing it to fail on so few occasions?

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.