BeGe
Вождь Апачей, блин (c)
XML + исходный код php
Как отобразить этот xml в HTML с подсветкой php кода.
Идея такая.... но что не получается....
PHP:
<?xml version="1.0" encoding="windows-1251"?>
<data>
<php>
<![CDATA[
<?php
/***************************************************************************
* common.php
* -------------------
* begin : Saturday, Feb 23, 2001
* copyright : (C) 2001 The phpBB Group
* email : [email][email protected][/email]
*
* $Id: common.php,v 1.2 2004/02/08 11:42:01 begemot Exp $
*
*
***************************************************************************/
/***************************************************************************
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
***************************************************************************/
if ( !defined('IN_PHPBB') )
{
die("Hacking attempt");
}
error_reporting (E_ERROR | E_WARNING | E_PARSE); // This will NOT report uninitialized variables
set_magic_quotes_runtime(0); //
?>
]]>
</php>
</data>
Идея такая.... но что не получается....
PHP:
<?
iconv_set_encoding("internal_encoding", "WINDOWS-1251");
iconv_set_encoding("output_encoding", "UTF-8");
$xml_data=file_get_contents("test.xml");
$xml_data=iconv("WINDOWS-1251","UTF-8",$xml_data);
$dom=domxml_open_mem($xml_data);
$root = $dom->document_element();
$code_elm=$root->get_elements_by_tagname("php");
foreach($code_elm as $element){
$str=$element->get_content();
$parent=$element->parent_node();
$old_name=$element->node_name();
$str=highlight_string($str,true);
$new_elm=$dom->create_element($old_name);
$new_elm->set_content($str); $parent->remove_child($element);
$parent->append_child($new_elm);
}
$xslData = file_get_contents("./template.xsl");
$xmlData = $dom->dump_mem();
$xh = xslt_create();
$arguments = array(
'/_xml' => $xmlData,
'/_xsl' => $xslData
);
$result = @xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);
if ($result)
echo $result;
else {
print ("There was an error that occurred in the XSL transformation...\n");
print ("\tError number: " . xslt_errno($xh) . "\n");
print ("\tError string: " . xslt_error($xh) . "\n");
exit;
}
?>