-2

I have a string like

"Geräumiges Studentenapartment in Aachens Fußgängerzone am Aquis Plaza!"

I want to remove the special character form the string. i have already used strip_tags and htmlspecialchars for this. but did not work.

Ranjit
  • 1,684
  • 9
  • 29
  • 61
  • those html entities look like letter characters. the first and last one are [A, umlaut](http://www.danshort.com/HTMLentities/index.php?w=latin) so you might want to make sure you want to really remove these outright or just convert them to a regular character – Memor-X Sep 23 '16 at 03:17
  • Just convert them to regular character. – Ranjit Sep 23 '16 at 03:19
  • There are no ***tags*** in this string to be removed. What exactly are you expecting the end-result to be here? – Sherif Sep 23 '16 at 03:19
  • I think You people are not reading the question before downgrade the question. Have you really cant understand what i mean. I need this function in php "html_entity_decode". Thank you for your interest. – Ranjit Sep 23 '16 at 03:35
  • Possible duplicate of [PHP remove special character from string](http://stackoverflow.com/questions/6073221/php-remove-special-character-from-string) – Sadikhasan Sep 23 '16 at 03:39

2 Answers2

0

You can use preg_replace to remove these special characters.

For example:

$output=preg_replace('/[^(\x20-\x7f)]*/s','',$string);
Ishita Sinha
  • 2,168
  • 4
  • 25
  • 38
0

Something like

function clean($string) {
   $string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.

   return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}

Usage:

echo clean('a|"bc!@£de^&$f g');

output:

abcdef-g

reference

Community
  • 1
  • 1
Elyor
  • 5,396
  • 8
  • 48
  • 76