Porting PHP5 to legacy PHP4, DOMDocument quibbles

瘦欲@ 提交于 2019-12-11 14:56:47

问题


I'm trying to make some of my php5 code work on a legacy server, which unfortunately cannot be upgraded (client's machine).

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;
            }


        }
    }

}

I've got as far as working out that domdocument is missing a ton of methods in php4 (it's php4.4.4, on a centos box), some of which seem to be replaced by global static functions.. .domxml_open_file()? The XML also has an encoding of UTF8, and the site is in ISO-8859-1..

Bottom line here is, I'm lost! How to make this stuff work on legacy php4? Are there any gotchas about using unicode on php4..?

Thanks.


回答1:


Well, I managed to get this going - fortunately, I found on ister.org a backport of php5's simpleXML functions, which work just fine on php4.4. I've rewritten a lot of the code, and it wasn't too tricky.

Hope this helps someone else in the future.



来源:https://stackoverflow.com/questions/3503276/porting-php5-to-legacy-php4-domdocument-quibbles

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!