Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6809443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:05:14+00:00 2026-05-26T20:05:14+00:00

I’m filtering all user input to remove the following characters: http://www.w3.org/TR/unicode-xml/#Charlist (not suitable characters

  • 0

I’m filtering all user input to remove the following characters:
http://www.w3.org/TR/unicode-xml/#Charlist (“not suitable characters for use with markup”).
So, I have this two functions:


if (!function_exists("mb_trim")) {
    function mb_trim($str)
    {
        return preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $str);
    }
}

function sanitize($str)
{
    // Clones of grave and accent
    $str = preg_replace("/[\x{0340}-\x{0341}]+/u", "", $str);

    // Obsolete characters for Khmer
    $str = preg_replace("/[\x{17A3}]+/u", "", $str);

    $str = preg_replace("/[\x{17D3}]+/u", "", $str);

    // Line and paragraph separator
    $str = preg_replace("/[\x{2028}]+/u", "", $str);

    $str = preg_replace("/[\x{2029}]+/u", "", $str);

    // BIDI embedding controls (LRE, RLE, LRO, RLO, PDF)
    $str = preg_replace("/[\x{202A}-\x{202E}]+/u", "", $str);

    // Activate/Inhibit Symmetric swapping
    $str = preg_replace("/[\x{206A}-\x{206B}]+/u", "", $str);

    // Activate/Inhibit Arabic from shaping
    $str = preg_replace("/[\x{206C}-\x{206D}]+/u", "", $str);

    // Activate/Inhibit National digit shapes
    $str = preg_replace("/[\x{206E}-\x{206F}]+/u", "", $str);

    // Interlinear annotation characters
    $str = preg_replace("/[\x{FFF9}-\x{FFFB}]+/u", "", $str);

    // Byte Order Mark
    $str = preg_replace("/[\x{FEFF}]+/u", "", $str);

    // Object replacement character
    $str = preg_replace("/[\x{FFFC}]+/u", "", $str);

    // Scoping for Musical Notation
    $str = preg_replace("/[\x{1D173}-\x{1D17A}]+/u", "", $str);

    $str = mb_trim($str);

    if (mb_check_encoding($str)) {
        return $str;
    } else {
        return false;
    }
}

I have not much knowledge with regular expresions, so, what I want to know is

  • Is the mb_trim function correct for trimming multi-byte strings?
  • Is it possible to join all regular expresions in the function
    sanitize to do only one preg_replace?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:05:15+00:00Added an answer on May 26, 2026 at 8:05 pm

    You can do with one preg_replace by combining them into a one character set like so:

     $str = preg_replace("/[\x{0340}-\x{0341}\x{17A3}\x{17D3}\x{2028}-\x{2029}\x{202A}-\x{202E}\x{206A}-\x{206B}\x{206C}-\x{206D}\x{206E}-\x{206F}\x{FFF9}-\x{FFFB}\x{FEFF}\x{FFFC}\x{1D173}-\x{1D17A}]+/u", "", $str);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I need a function that will clean a strings' special characters. I do NOT
I want to count how many characters a certain string has in PHP, but
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.