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
https://forums.phpfreaks.com/topic/108253-solved-replaceregex-question/
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"

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

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.