How do i remove special characters from a string in html?
I'd like to use any php function or whatever so that i can remove any HTML code and special characters and gives me only alpha-numeric output Show
I want the output become I've tried
So is there any way to do it?
Martijn 15.5k4 gold badges36 silver badges66 bronze badges asked Aug 20, 2011 at 1:03
Reham FahmyReham Fahmy 4,80315 gold badges49 silver badges70 bronze badges Probably better here for a regex replace
Or, in one go
answered Aug 20, 2011 at 1:07
9 Strip out tags, leave only alphanumeric characters and space:
Edit: all credit to DaveRandom for the perfect solution...
answered Aug 20, 2011 at 1:06
Matt SteinMatt Stein 3,0441 gold badge18 silver badges34 bronze badges 1 All the other solutions are creepy because they are from someone that arrogantly simply thinks that English is the only language in the world :) All those solutions strip also diacritics like ç or à. The perfect solution, as stated in PHP documentation, is simply:
answered Feb 22, 2017 at 21:49
1
In a more detailed manner from Above example, Considering below is your string:
Code:
answered Dec 24, 2013 at 12:44
Aditya P BhattAditya P Bhatt 20.6k17 gold badges81 silver badges103 bronze badges 2 You can do it in one single line :) specially useful for GET or POST requests
answered Feb 6, 2014 at 20:08
nodwsnodws 92013 silver badges18 bronze badges Here's a function I've been using that I've put together from various threads around the net that removes everything, all tags and leaves you with a perfect phrase. Does anyone know how to modify this script to allow periods (.) ? In other words, leave everything 'as is' but leave the periods alone or other punctuation like and ! or a comma? let me know.
answered May 9, 2015 at 23:22
ViktorViktor 4973 silver badges21 bronze badges 1 to allow periods and any other character just add them like so: change: '
sandip 5239 silver badges24 bronze badges answered Jan 28, 2016 at 0:04
answered Apr 25, 2017 at 4:34
Remove all special character don't give space write in single line
Pang 9,192146 gold badges85 silver badges118 bronze badges answered Jul 16, 2017 at 22:39
How do you remove special characters in HTML?This should do what you're looking for: function clean($string) { $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens. return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. } Hope it helpss!!
How do I remove special characters from a string?Example of removing special characters using replaceAll() method. public class RemoveSpecialCharacterExample1.. public static void main(String args[]). String str= "This#string%contains^special*characters&.";. str = str.replaceAll("[^a-zA-Z0-9]", " ");. System.out.println(str);. How do I remove a character from a string in HTML?Using a replace() method with a regular expression
To remove a character from a string, use string replace() and regular expression. This combination is used to remove all occurrences of the particular character, unlike the previous function.
How do I remove special characters and spaces from a string?Use the replace() method to remove all special characters from a string, e.g. str. replace(/[^a-zA-Z0-9 ]/g, ''); . The replace method will return a new string that doesn't contain any special characters.
|