XML:
<programme start="20180124160000 +0200" stop="20180124164500 +0200" channel="506"><title lang="he">
ריזולי ואיילס 7 11. הגופה</title><desc lang="he">
מתח. 11. הגופה: גופתו של קברן נמצאת בתוך ארון קבורה של אחד מלקוחותיו והדבר מוביל את חברי הצוות לחשיפת גופות נוספות. ג'יין מבשרת לקרוביה על החלטתה לעבור לאף.בי.איי.</desc></programme></programmes>
I want to remove from the text all the
How to remove it with str_replace?
PHP:
$c = $xpath->query("div[@class = 'show']/text()", $container)->item(0);
$desc = $c->nodeValue;}
$desc = str_replace(" ", "", $desc);
$echo desc;
It seems that somewhere along the line, the string has been html-encoded.
You can decode it again using:
html_entity_decode('thisisa test')
or:
html_entity_decode($your_encoded_string)
See here how it works.
The parser will do it for you:
$document = new DOMDocument();
$document->loadXml('<foo> </foo>');
var_dump($document->documentElement->textContent);
Output:
string(1) "
"
The var_dump() output shows that the string contains only a single character - a carriage return. However the parser will do this only for normal text nodes, not for CDATA sections:
$document = new DOMDocument();
$document->loadXml('<foo><![CDATA[ ]]></foo>');
var_dump($document->documentElement->textContent);
Output:
string(5) " "
In this you need to use string functions to replace the entity manually.
Tip: With DOMXpath::evaluate()
you can fetch the text content directly as a string by using the string
function to cast the node list:
$description = $xpath->evaluate("string(div[@class = 'show'])", $container);