Parsing of self-written marking language, PHP



  • Format of file

    <first>Items name</first>
    <second>
        Item:one more
        Item:one more
    </second>
    

    The code is:

    if(($result = file_get_contents(FILENAME)) === false) die('failed to open or read file');
    $result = explode("\n", $result);
    foreach ($result as $string) {
        // ?
    }
    

    Instead of commenting, I would like to remove the meaning between <first>
    Sscanf Read it. ItemsIf you make a mask <first>%s</first>

    How else can this matter be removed?



  • You need to read HML pasting on php. http://php.net/manual/ru/simplexml.examples-basic.php ♪

    if ($content = file_get_contents(FILENAME)) {
        $xml = new SimpleXMLElement($content);
        $first = $xml->first;
        echo($first);
    }
    

    In addition to SimpleXMLElement, there are more advanced solutions, such as: DOMDocument (established in PHP), simplehtmldom was very good and resembled jQuery, but has not been updated long ago.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2