Today, We want to share with you remove special characters from string php.In this post we will show you php removes multiple characters from string, hear for removes html special character from string php we will give you demo and example for implement.In this post, we will learn about Use the PHP htmlspecialchars() function with an example.
remove special characters except space from string php
In this tutorial we learn to all about removes special character from string php Examples like as a remove from string php, removes specific character, php remove multiple characters or many more.
Remove all special characters from a string
function clean($allCleanString) { $allCleanString = str_replace(' ', '-', $allCleanString); return preg_replace('/[^A-Za-z0-9\-]/', '', $allCleanString); } echo clean('a|"bc!@£de^&$f g');
Using str_replace() Method:
' ), ' ', $allCleanString); return $res; } $allCleanString = "Example,to removeSpecial'Char;"; $allCleanString = RemoveSpecialChar($allCleanString); echo $allCleanString; ?>
You can also check other tutorial of string,
- Removes Special Characters From String Php
- MySQL Remove Special Characters From Database
- Remove Null Values From Array In PHP
Using str_ireplace() Method:
' ), ' ', $allCleanString); return $res; } $allCleanString = "Example,to removeSpecial'Char;"; $allCleanString = RemoveSpecialChar($allCleanString); echo $allCleanString; ?>
Using preg_replace() Method
Special'Char;"; $allCleanString = RemoveSpecialChar($allCleanString); echo $allCleanString; ?>
seo friendly url using PHP
function seo_friendly_url($user_str_data){ $user_str_data = str_replace(array('[\', \']'), '', $user_str_data); $user_str_data = preg_replace('/\[.*\]/U', '', $user_str_data); $user_str_data = preg_replace('/&(amp;)?#?[a-z0-9]+;/i', '-', $user_str_data); $user_str_data = htmlentities($user_str_data, ENT_COMPAT, 'utf-8'); $user_str_data = preg_replace('/&([a-z])(acute|uml|circ|grave|ring|cedil|slash|tilde|caron|lig|quot|rsquo);/i', '\\1', $user_str_data ); $user_str_data = preg_replace(array('/[^a-z0-9]/i', '/[-]+/') , '-', $user_str_data); return strtolower(trim($user_str_data, '-')); }
I hope you get an idea about removes specials character from string php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.