Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: PREC Modifers

  1. #11
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    good question. \b is a bit harder to understand; at least for me it was. \b is the boundary between a word character and a non word character. For example

    $test='####tttt';
    $test=preg_replace('/\b/','correct',$test);
    echo "$test";

    // this produces: ####correcttttt

    I wasn't sure how to do what you wanted without \b, because it would have failed under certain circumstances.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. The Following User Says Thank You to james438 For This Useful Post:

    bluewalrus (12-28-2010)

  3. #12
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Thanks, yes that could did work I finally got around to finishing my word/open office/ckeditor convertor.

    I don't have a mark as resolved option anymore though I guess maybe an admin will mark it for me.
    Corrections to my coding/thoughts welcome.

  4. #13
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I've returned with a varied question (this one is to remove duplicating tags). I've got this code now

    PHP Code:
    $code_is preg_replace('/<([a-z,A-Z].*?)>\s+<\1>/s'" <$1>"$code_is);
    //initially had $code_is = preg_replace('/<(.*?)>\s+<\1>/s', " <$1>", $code_is);
    $code_is preg_replace('/<(\/.*?)><\1>/s'"<$1> "$code_is); 
    which is suppose to filter something like

    <em> <em>et al.</em></em>
    to

    <em>et al.</em>
    Well it works there it is deleting <td> tags entered like this

    <td>&nbsp;</td>
    <td>&nbsp;</td>
    which becomes

    <td>&nbsp;</td>
    Corrections to my coding/thoughts welcome.

  5. #14
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    We should probably try and get a moderator to split this thread.

    Anyway

    PHP Code:
    <?php
    $code_is
    ="<em> <em>et al.</em></em>
    <td>&nbsp;</td>
    <td>&nbsp;</td>"
    ;
    $code_is preg_replace('/<([a-zA-Z].*?)>\s*<\1>/s'" <$1>"$code_is); 
    $code_is preg_replace('/<(\/.*?)><\1>/s'"<$1> "$code_is);
    echo 
    $code_is;
    ?>
    I didn't look too closely into why it wasn't working. All I did was fix a few of the more obvious errors and then tried it out again and it seems to be working.

    EDIT: This is a little better though:

    Code:
    $code_is = preg_replace('/<([a-zA-Z].*?)>\s*<\1>/si', " <$1>", $code_is); 
    $code_is = preg_replace('/<(\/.*?)><\1>/si', "<$1> ", $code_is);
    Last edited by james438; 12-29-2010 at 10:26 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

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
  •