将PHP5移植到遗留PHP4,DOMDocument狡辩

时间:2010-08-17 14:06:37

标签: php xml legacy php4 domdocument

我正在尝试让我的一些php5代码在遗留服务器上运行,遗憾的是无法升级(客户端的机器)。

if (!isset($docRoot)) {
    $docRoot = $_SERVER['DOCUMENT_ROOT'];
}

// generic storage class for the words/phrases
$t = new stdClass();
$t->lang = $curPage->lang;



// load xml translations, could split this into different files..
$translations = new DOMDocument();
$translations->load($docRoot."/xml/translations.xml");

$words = $translations->getElementsByTagName("word");
$count = 0;
foreach( $words as $word )
{

    $name = $word->getAttribute('name');
    $trans = $word->childNodes;

    if ($trans->length > 0) {
        for($i = 0; $i < $trans->length; $i++) {
            $child = $trans->item($i); 



            if ($child->nodeName == $curPage->lang) {
                $t->$name = $child->nodeValue;
            }


        }
    }

}

我已经知道domdocument缺少php4中的大量方法(它是php4.4.4,在centos盒子上),其中一些似乎被全局静态函数替换..。{{ 1}? XML也有UTF8编码,站点在ISO-8859-1 ..

这里的底线是,我输了!如何让这些东西在遗留的php4上工作?有没有关于在php4上使用unicode的问题..?

感谢。

1 个答案:

答案 0 :(得分:1)

好吧,我设法让这一切 - 幸运的是,我在ister.org找到了php5的simpleXML函数的后端,它在php4.4上运行得很好。我已经重写了很多代码,并不是太棘手。

希望将来可以帮助其他人。

相关问题