Reputation: 59
I am displaying content from database to xml file .In that some special character are displaying like.. world,rdquo , Caper,rdquo ,donrs , ldhe , ndash , Isnrs.
How can we remove this character .Please tell me the solutions.
Upvotes: 1
Views: 87
Reputation: 32260
The "special characters" are correct because their original presentation is not allowed inside an XML document.
Consider this link: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
When using the XML file, you turn the characters back either automatically by the XML library or manually by using html_entity_decode()
- http://www.php.net/manual/en/function.html-entity-decode.php
So when you want to change them INSIDE the XML document, this is against the rules for XML documents. You don't want to change them. You don't need to change them. If you don't want those characters, don't use XML. Use custom CSV then or whatever does not include escaping characters in their format.
If you want to change the characters AFTER processing the XML file:
echo html_entity_decode((string)$xml->node);
Upvotes: 1
Reputation: 1393
if you want to replace special character then use preg_replace()
$string="a$#rsdg123^";
echo preg_replace('/[^A-Za-z0-9\-\']/', '', $string);
output: arsdg123
Upvotes: -1
Reputation: 776
If you have specific set of "special character" like you mentioned(only if), then define an array of those words/characters then replace it with blank value.
for example:
$splChar = array("world","rdquo","Caper","rdquo","donrs","ldhe","ndash","Isnrs");
$requiredContent = str_ireplace($splChar, "", $yourContent);
Note: Here str_ireplace is Case-insensitive
Upvotes: 1