#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2014
    Posts
    3
    Rep Power
    0

    Remove Non Printable Characters Except Currency Symbols


    I want to remove non printable char charcaters from a string but retain currency symbols

    This strips all but non printable but I want to keep currency symbols too, how to add an exception for currency symbols please?

    Code:
    $str = preg_replace('/[[:^print:]]/', '', $str);
    I believable this matches currency symbols:

    Code:
    \p{Sc}
    How to combine please, I can't get it to work?
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,434
    Rep Power
    9645
    1. Change the character set from "any character which is (not printable)" to "any character which is not (printable)". You'll be moving the ^.
    2. Add \p{Sc} into the character set. Make sure you add it in the right place.

    The result will be "any character which is not (printable or a currency symbol)".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2014
    Posts
    3
    Rep Power
    0
    This is the answer for anyone looking for this:

    $str = preg_replace('/(*UTF)[^[:print:]\p{Sc}]+/', '', $str);


    Originally Posted by energylevels
    I want to remove non printable char charcaters from a string but retain currency symbols

    This strips all but non printable but I want to keep currency symbols too, how to add an exception for currency symbols please?

    Code:
    $str = preg_replace('/[[:^print:]]/', '', $str);
    I believable this matches currency symbols:

    Code:
    \p{Sc}
    How to combine please, I can't get it to work?
    Last edited by requinix; December 1st, 2016 at 01:30 AM. Reason: disable smilies

IMN logo majestic logo threadwatch logo seochat tools logo