Get the contents of a specified tag from an XML file in PHP


/ Published in: PHP
Save to your folder(s)

Simple piece of PHP to get the contents of a specified tag from an XML file and return it


Copy this code and paste it in your HTML
  1. //Get the contents of a specified tag ($tag) of the specified XML file ($xmlFile)
  2. function getXmlData($xmlFile, $tag)
  3. {
  4. $output = substr($xmlFile, strpos($xmlFile, "<".$tag.">") + strlen("<".$tag.">"),
  5. strpos($xmlFile, "</".$tag.">")- strpos($xmlFile, "<".$tag.">") - strlen("<".$tag.">"));
  6. return $output;
  7. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.