PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 20, 2022

[FIXED] how to remove special chars like this █ from string in php

 November 20, 2022     php, preg-replace, special-characters     No comments   

Issue

how to remove only this type of special chars ░▒▓█► from a string in php I use this preg_replace('/[\x00-\x1F\x80-\xC0]/u', '',$string);

but i want to allow special char like à,â, ', ", for french language


Solution

You can use unicode character classes like \p{Latin} for latin script, \p{Sc} for currency, \p{P} (or shorter \pP) for punctuation characters:

$str = preg_replace('/[^0-9\p{Latin}\pP\p{Sc}@\s]+/u', '', $str);

You can find the different unicode character classes available in PCRE here. (search the sentence: "The following general category property codes are supported")



Answered By - Casimir et Hippolyte
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing