xyn Posted June 1, 2008 Share Posted June 1, 2008 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... Quote Link to comment Share on other sites More sharing options...
xyn Posted June 1, 2008 Author Share Posted June 1, 2008 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" Quote Link to comment Share on other sites More sharing options...
effigy Posted June 2, 2008 Share Posted June 2, 2008 <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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.