WikiWords with _underscore_ :: Help with regex statement

Discussion in 'PHP' started by ErectADirectory, Feb 27, 2007.

  1. #1
    Greetings fellow PHPeeps,

    I am dropping a wiki in place for a family web site I am doing for a client and was wondering if someone has done what I am trying to do as I hate re-inventing the wheel.

    The problem is this. I want to make WikiPages with underscores so it will be easy to parse names out of the pages with str_replace (eg. "First_Middle_Last" becomes "First Middle Last". So I have 2 ways to approach this problem.

    1. I can find a way to do a regex that finds all capital letters after the first character {2,} and replace it with whitespace then that character. FirstMiddleLast --> First Middle Last

    2. I can find a way to strip the underscore "_" out of text to make a WikiWord for normal parsing. The trick to this is that I would like the linked word to contain the underscore (or whitespace).

    Here is the line in the code that does the WikiWord thing.

    $filtered = preg_replace("/(?<=\s)([A-Z][a-z0-9äöüß\&]+){2,}/","<a href=\"index.php?$wiki_get=\\0\">\\0</a>", $filtered);
    
    PHP:
    I think my problem is clearer to understand that my solutions above. Any help would be appreciated as I am sure someone has tackled this in the past. I'm sure there is an easy solution, I just hope to have it donated instead of searching for this.

    thanks in advance for letting me borrow a few of your brain cells,
    Josh
     
    ErectADirectory, Feb 27, 2007 IP
  2. ErectADirectory

    ErectADirectory Guest

    Messages:
    656
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Thanks to Nico_swd for answering this on a different thread. Answer posted here for future users


    $string = "ErectADirectoryIsAGeek" ;
    // Reverse
    $string = preg_replace('/[A-Z]/e', "' ' . '$0'", $string);
    echo $string . "<br /><br />" ;
    // prints Erect A Directory Is A Geek 
    PHP:
    Some WikiWords of my own ... YouDManNico
     
    ErectADirectory, Apr 24, 2007 IP