PHP code op pagina uitvoeren
-
Hallo,
Voor een autobedrijf moet ik PHP code integreren om advertenties (via een portal) op te halen.
Nou wil ik dit op een specifieke pagina van de site weergeven.
De code die hiervoor nodig is bevat 2 bestanden:
index.php<?php error_reporting(E_ALL); ini_set("display_errors", "on"); include_once("xml.class.php"); //hier post informatie //$xmlData = file_get_contents("php://input"); //zo ziet de output eruit. $xmlData = file_get_contents("input/xmlinput-1342704070.xml"); $fh = fopen("input/xmlinput-" . time() . ".xml", "w"); fwrite($fh, $xmlData); fclose($fh); $xml = new vweXML(); $xml->setVar("XMLinput", $xmlData); $result = $xml->processXMLcontent(); //$result = $xml->getResult(); $result = $xml->getVar("XMLoutput"); echo '<pre>'; var_dump($result); ?>
En xml.class.php
<?php class vweXML { /** * XML input */ protected $XMLinput; /** * XML output */ protected $XMLoutput; /** * XMLReader object */ protected $doc; /** * Last error message */ protected $error; /** * Proces result */ protected $result; /** * Process the XML content * * @return void */ public function processXMLcontent( ) { if ( isset( $this->XMLinput ) ) { if ( ! isset( $this->XMLoutput ) ) { $this->doc = new XMLReader( ); //Parse XML document if ( $this->doc->XML( stripslashes( $this->XMLinput ) ) ) { //Convert the document to an array if ( $this->XMLoutput = $this->xml2assoc( ) ) { $this->doc->close( ); return true; } } $this->doc->close( ); $this->setResult( "Incorrect XML format" ); return false; } else { return $this->XMLoutput; } } else { $this->setResult( "No XML input was found" ); } return false; } /** * XML to associative array * * @return void */ protected function xml2assoc( ) { $tree = null; while ( $this->doc->read( ) ) { switch ( $this->doc->nodeType ) { case XMLReader::END_ELEMENT: return $tree; case XMLReader::ELEMENT: $node = array( 'tag' => $this->doc->name, 'value' => $this->doc->isEmptyElement ? '' : $this->xml2assoc( $this->doc ) ); if ( $this->doc->hasAttributes ) { while( $this->doc->moveToNextAttribute( ) ) { $node['attributes'][ $this->doc->name ] = $this->doc->value; } } $tree[] = $node; break; case XMLReader::TEXT: case XMLReader::CDATA: $tree .= $this->doc->value; } } return $tree; } /** * Retrieves a var from the object * * @param string $var * @return mixed $var */ public function getVar( $var ) { if ( isset( $this->$var ) ) { return $this->$var; } return false; } /** * Sets a var in the object * * @param string $var * @param mixed $value * @return bool */ public function setVar( $var, $value ) { if ( property_exists( $this, $var ) ) { $this->$var = $value; return true; } return false; } /** * Sets result message * * @param string $message */ protected function setResult( $message ) { if ( $message ) $this->result = $message; } /** * Returns result */ public function getResult( ) { if ( isset( $this->result ) ) return $this->result; return false; } } ?>
Enig idee hoe dit op een pagina te implementeren ?
4 reacties aan het bekijken - 1 tot 4 (van in totaal 4)
4 reacties aan het bekijken - 1 tot 4 (van in totaal 4)
- Het onderwerp ‘PHP code op pagina uitvoeren’ is gesloten voor nieuwe reacties.