SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Did I mess up my preg_replace?

    Code PHP:
     $text = preg_replace('|\[Quote:(.+?)\](.+?)\[\/Quote\]|i','<blockquote><div><strong>$1</strong></div>$2</blockquote>', $text);

    Did I mess up something in the preg_replace? It's post to preg_replace this type of text:

    [Quote:blake] blah blah blah [/Quote]

    The last tag is also uppercase Q since it doesn't seem to be rendering right in the forums.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,448
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)
    Although indiscriminate use of the everything atom - (.+?) - can lead to problems. the code seems to work OK when $text is a single line. If it is on more than one line, try the "PCRE_DOTALL" modifier - ....|si'

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2008
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow that was my problem, some of the quotes expanded more then one line. So the "PCRE_DOTALL" modifier - ....|si" fixed it, thanks Mitt!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •