www.webdeveloper.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19

Thread: Having trouble with my preg_replace_callback()

  1. #16
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Quote Originally Posted by jeddik View Post
    Oh - and you may notice I still used my (.+?)
    what was the advantage of ([\w\W]*?) ??
    Your expression will work with single lined data, if for some reason the content between your tags spanned multiple lines then the expression would not match.
    . Matches any single character except "\n". To match any character including the '\n', use a pattern such as '[\s\S]'.
    I used [\w\W], but it's the same thing really.

    I'm not sure about how to pass extra parameters to a callback at the moment, I probably would have used a global variable, but I'm not going to say more about to save face :P
    Last edited by bionoid; 12-23-2013 at 05:23 PM.
    JavaScript: Learn | Validate | Compact | bionoid

  2. #17
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,247
    Note that you can add a "s" modifier after the closing regex delimiter to have the dot character include newlines.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #18
    Join Date
    May 2006
    Posts
    245
    OK - thanks to both.

    I added/changed these lines then:

    global $lang_cd;

    and this:

    PHP Code:
    $test_output2 preg_replace_callback(
        
    '/\[hd[1-6]\](.+?)\[\/hd\]/s',
        
    'titleCase',
        
    $test); 
    Seems to be working OK

    .
    Developers Choice Revealed:
    www.devchoice.info
    Which host has won, and why ?

  4. #19
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    Quote Originally Posted by NogDog View Post
    Note that you can add a "s" modifier after the closing regex delimiter to have the dot character include newlines.
    Good to know.

    The description I posted was from the JavaScript RegExp object, and didn't think to look if PHP had its own proprietary flags.
    For anyone interested in the possible pattern modifiers: http://php.net/manual/en/reference.p....modifiers.php
    JavaScript: Learn | Validate | Compact | bionoid

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles