#1
  1. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,007
    Rep Power
    175

    How to replace consecutive appearance of a characters with only 1?


    Hi;

    I want to replace >> or >>> or >>>> or any variairon of multiple appearances of > with only one >

    For example:

    Code:
    test.com>>test2.com>>>>test3.com>test.com
    Becomes
    Code:
    test.com>test2.com>test3.com>test.com

    Would this be reliable?

    Code:
    $_POST['list_of_embed_items'] = preg_replace('/>{2,}/','>',$_POST['list_of_embed_items']);
    Thanks
    Last edited by English Breakfast Tea; March 17th, 2017 at 12:20 AM.
  2. #2
  3. Confusing Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    15,923
    Rep Power
    9570
    Does it work? Because it looks fine to me.

    But
    PHP Code:
    $_POST['list_of_embed_items'] = 
    don't do that. Leave $_POST (and $_GET and whatever) unchanged. Best practice. Put the altered value into a new variable somewhere.
  4. #3
  5. A Change of Season
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Mar 2004
    Location
    Next Door
    Posts
    3,007
    Rep Power
    175
    I wish I could lock you in a room for 24 hours and ask you all my questions one by one, face to face on my laptop.

IMN logo majestic logo threadwatch logo seochat tools logo