0

I have a string with special characters like doublequote " or comma or hypen

For example:

$str= "156- Police, 132 - Medical, 119 - Fire";

output should be

$newstr = "156 - Police, 132 - Medical, 119 - Fire"

I am trying to do it with str_replace function in php as

$chars = array('"', "'", ",","-",".");
$speChars   = array("&#34", "&#39", "&#44","&#45","&#46");
$newStr = str_replace($str, $chars, $speChars);

But it didnot work. Could anyone please help me to figure out this issue?

DSKVP
  • 653
  • 1
  • 11
  • 19
  • 2
    Those are not generally "special" characters in XML, there's no reason to replace them. If you insert them into XML you should do so with an XML writer which takes care of that. – deceze May 02 '14 at 17:06
  • The first two - which don't appear in your string - are easily encoded using `htmlspecialchars()`. or `htmlentities()`. – jeroen May 02 '14 at 17:07
  • http://stackoverflow.com/questions/3426090/how-do-you-make-strings-xmlsafe – TurboHz May 02 '14 at 17:25
  • Thanks for the ideas. I got it :) – DSKVP May 02 '14 at 17:56

0 Answers0