keskiviikko 15. helmikuuta 2017

PHP - file_contents()

Joskus pitää käsitellä HTML-sivulle tuotua XML- koodia. File_contents osaa purkaa xml:n sisällön HTML:n sekaan, mutta voi olla, että haluat nähdä myös XML-rakenteen.
Se onnistuu tällä vinkillä:
When you print XML in an HTML page, the XML is assimilated to HTML, so you do not see the tags.
To see the tags as text, you should replace them with the HTML corresponding entity:
$myxmlfilecontent = file_get_contents('./myfile.xml');
echo str_replace('<', '&lt;', $myxmlfilecontent);
that should do the trick

Ei kommentteja:

Lähetä kommentti