How can I debug my php code?

PHP question.

  • Ok, another PHP question... this one less stupid than my last one (hopefully). XML/XSLT.... [mi] I have some generated XML (from a php script that builds from a directory and contents)... I used and modified some code to do a transform: /** * * A class to transform XML through XSLT using PHP4 Sablotron extension * */ ####################################################################### ## file extended by Daniel Unterberger ([email protected]) ## changes: some php:eval's added class xsltTransform { var $xsl_file; var $xml_file; var $fileName; /** * Constructor to the xsl_transform ticket * * @param $xsl_file The XSLT file containing the transformation info * @param $xml_file The XML file containing the actual data * @see readFile() */ function xsltTransform($xsl_file = '', $xml_file = '') { if($xsl_file{0} == "/") # this is a relative path, so use the file { $this->xsl_string = "file://".$_SERVER['DOCUMENT_ROOT'].$xsl_file; } else { $this->xsl_string = $this->readFile($xsl_file,'php:eval'); } if($xml_file{0} == "/") # this is a relative path, so use the file { $this->xml_string = "file://".$_SERVER['DOCUMENT_ROOT'].$xml_file; } else { $this->xml_string = $this->readFile($xml_file); } } /** * Function to read through the file * * @param $fileName Which file to read? * */ function readFile($fileName,$php_eval="") { // get contents of a file into a string $fd = fopen( $fileName, "r" ); while (!feof ($fd)) { $content .= fgets($fd, 4096); #?rtrim } fclose( $fd ); ################################################## ## extension by Daniel Unterberger ([email protected]) while ( $php_eval and ( $pos_start=strpos($content,'') )) { $pos_end=strpos($content,''); $content=substr($content,0,$pos_start). eval( substr($content,$pos_start+10,$pos_end-$pos_start-10) ). substr($content,$pos_end+11); } if ($GLOBALS["debug"]=="ON") print "$content"; ## see xslt-file for debuggin if you call page.php?debug=ON (remove on life-server) ################################################### ## end extension return $content; } /** * Function to apply the actual transformation * */ function applyTransformation() { $xh = xslt_create(); # $this->result = ''; $this->result = xslt_process($xh, $this->xml_string, $this->xsl_string); if(!$this->result) { print ("Transformation failed; Error String:".xslt_error($xh)."; Err #:".xslt_errno($xh).""); print ("XSL:-".$this->xsl_string."-"); print ("XML:-".$this->xml_string."-"); } xslt_free($xh); return $this->result; } // End of class, do not remove } ?> > now the if I generate the XML and save it to the file system, then give the function xsltTransform the actual file path the transform work fine. However, if I read it from the webserver using http:// (where it was generated from) I can print it to the screen. However, but the call to $this->result = xslt_process($xh, $this->xml_string, $this->xsl_string); in applyTransformation fails indicating that the XML is badly formed (error 4). Any advice from our PHP gurus?

  • Answer:

    xslt_process() is a bit touchy and tries to guess whether you're submitting a string of xml or a path. What's your input to each function? Can you make reproduce it with a simpler example?

pissfactory at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.