Jump to content
  • Advertisement
Sign in to follow this  
Brocketino

[web] preg_replace

This topic is 4866 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Can some1 tell me what im doing wrong here, I want every [xxx][/xxx] tagpair converted to paragraphs and the text between them should be formated as bold, only if the value of the text is either 'first' or 'second'.
function parse($str)
{
  //
  // Change all occurances of [xxx][/xxx] and the text between them
  //
  while(preg_match("/(\[xxx\])(.+?)(\[\/xxx\])/s",$str,$result))
  {
    // Make bold if first or second
    $block = preg_replace("/\b(first|second)\b/","\\1",$result[2]);
    // Replace custom tags and insert formated block
    $str = preg_replace("/(\[xxx\])(.+?)(\[\/xxx\])/s","

$block

"
,$str); } return $str; }

Share this post


Link to post
Share on other sites
Advertisement
I am terrible with regular expressions, you should try the Regex Coach so you can see what the results would be realtime. Makes it very handy for testing those sort of regular expressions out.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!