Jump to content

[SOLVED] replace/regex question...


xyn

Recommended Posts

I currently have a regular expression... however I dont really want to use replace, even if i did, i'm still stuck. Basically im using  regular expressions to create a quote kinda of thing.

 

Basically if i did the following code, i'd get a div inside another div. ()gnoring any dots between tags)

[.quote=John says:]test [.quote=bob says] lala lala llala[./quote][./quote]

 

I'm currently using the following expressions:

$x ="/\[(quote)=(.*?)\](.*?)\[\/(quote)\]/i";
$y ="<div class=\"bbquote\">\\2<br /><br />\\3</div>";
$z =preg_replace($x,$y,$string);

 

However all of the quotes are text, except for the last quote tags sets, which are then the div which i wanted...

Link to comment
Share on other sites

Ok i kind of fixed it.

 

Basically this is now my new regexp

 

"/\[(quote)=(.*?)\](.*?)\[\/(quote)\]/is"

 

however this is the output:

<div style="bb">bob says:<br /><br />fgfdgfd<br />[.quote=john says:] dfg dggfdg[./quote]</div>

 

As you see i need to make each QUOTE /QUOTE its own pair; i failed with the following attempts:

"/\[(quote)=(.*?)\](.*?)\[\/(quote)\]/is"
"/^\[(quote)=(.*?)\](.*?)\[\/(quote)\]$/s"
"/(^\[(quote)=(.*?)\](.*?)\[\/(quote)\]$)/is"
"/(\[(quote)=(.*?)\](.*?)\[\/(quote)\])/is"

Link to comment
Share on other sites

<pre>
<?php
$string = '[quote=John says:]test [quote=bob says] lala lala llala[/quote][/quote]';
$pattern = '%\[quote=(.*?)\](.*?)\[/quote\]%i';
$replacement = '<div class="bbquote">\\2<br /><br />\\3</div>';
while (preg_match($pattern, $string)) {
	$string = preg_replace($pattern, $replacement, $string);
}
echo htmlspecialchars($string);
?>
</pre>

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.