[英]Problems after upgrading to PHP 5.2.6
I am in a predicament here. 我在这里陷入困境。 My PHP code used to work but since I upgraded to PHP 5.2.6 I now get:
我的PHP代码曾经可以使用,但是自从我升级到PHP 5.2.6以来,我得到了:
Warning: domdocument::domdocument() expects parameter 2 to be long, string given in C:\xamps older\xampp167\htdocs\test\myphp\CSR Demo pack\csr\output.php on line 46
Fatal error: Call to undefined method domdocument::loadHTML() in C:\xamps older\xampp167\htdocs\test\myphp\CSR Demo pack\csr\output.php on line 50
Here is the source: 来源如下:
<html>
<head>
</head>
<body>
<?php
//error_reporting(0);
/********** outputer **********/
$bool=file_exists("data/tcmpsr.txt");
if ($bool == 1)
{
$numstr=file_get_contents("data/tcmpsr.txt");
if ($numstr <> "")
{
$NumOfTitleChars= $numstr;
}
}
Else
{
}
$bool=file_exists("data/dcmpsr.txt");
if ($bool == 1)
{
$numstr=file_get_contents("data/dcmpsr.txt");
if ($numstr <> "")
{
$NumOfDtlChars = $numstr;
}
}
Else
{
}
/*** A new DOM object ***/
$dom = new DOMDocument('1.0','utf-8');
/*** load the html into the object ***/
$html = file_get_contents("data/csr.html");
$dom->loadHTML($html);
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
/*** get the tags by its tag name ***/
$artclArray = $dom->getElementsByTagName('div');
$hdArray = $dom->getElementsByTagName('h2');
$spanArray = $dom->getElementsByTagName('span');
$i=0;
$x=0;
$y=0;
$z=0;
foreach ($artclArray as $memberid)
{
$divArray[$x]=$memberid->nodeValue;
$x++;
}
foreach ($hdArray as $memberid)
{
$hdlsArray[$y]=$memberid->nodeValue;
$y++;
}
foreach ($spanArray as $memberid)
{
$dtlsArray[$z]=$memberid->nodeValue;
$z++;
}
$hdsele=0;
foreach($hdlsArray as $elemid)
{
$AmountOfHdlChars=$NumOfTitleChars;
$eachTitle=$elemid;
for ($count=0; $count<$AmountOfHdlChars; $count++)
{
$chara[$count]=$eachTitle[$count];
}
$smallTitle=implode($chara);
$shortTitleArray[$hdsele]=$smallTitle;
$hdsele++;
}
$dtlele=0;
foreach($dtlsArray as $elemid)
{
$AmountOfDtlChars=$NumOfDtlChars;
$eachDetail=$elemid;
for ($count=0; $count<$AmountOfDtlChars; $count++)
{
$chara[$count]=$eachDetail[$count];
}
$smallDtl=implode($chara);
$shortDtlArray[$dtlele]=$smallDtl;
$dtlele++;
}
//echo "".$shortTitleArray[0]."<br />";
//echo "".$shortDtlArray[0]."<br />";
//echo "".$divArray[0]."<br />";
//The Result is three arrays "shortTitleArray", "divArray" and //"shortDtlArray".
//hdlsArray and dtlsArray contain full actual headlines and details.
/******************************/
?>
</body>
</html>
After doing some research online I found that Zend extensions could be the cause. 在网上进行了一些研究之后,我发现Zend扩展名可能是原因。 Here is what my Zend setup looks like.
这是我的Zend设置的样子。
This program makes use of the Zend Scripting Language Engine: Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies with the ionCube PHP Loader v3.1.34, Copyright (c) 2002-2009, by ionCube Ltd., and with Zend Extension Manager v1.2.0, Copyright (c) 2003-2007, by Zend Technologies with Zend Optimizer v3.3.3, Copyright (c) 1998-2007, by Zend Technologies 该程序使用Zend脚本语言引擎:Zend Engine v2.2.0,版权所有(c)1998-2008 Zend Technologies与ionCube PHP Loader v3.1.34,版权所有(c)2002-2009,由ionCube Ltd.和Zend Extension Manager v1.2.0,版权所有(c)2003-2007,由Zend Technologies与Zend Optimizer v3.3.3,版权所有(c)1998-2007,由Zend Technologies
I have tested this code on several new Windows systems and it has failed on all. 我已经在几个新的Windows系统上测试了此代码,但所有代码都失败了。 This leads me to believe that most, if not many, webhosts might be using a similar setup to the one I have.
这使我相信,大多数(如果不是很多)网络主机可能使用的设置与我的设置相似。 The common solution, based on what I have read, is to disable Zend or comment out specific areas of the
php.ini
file. 根据我所读的内容,常见的解决方案是禁用Zend或注释掉
php.ini
文件的特定区域。 Because this is part of a script meant for distribution, most of my customers will not have direct access to the php.ini
nor have access rights to modify webserver settings such as Zend extensions. 因为这是用于分发的脚本的一部分,所以我的大多数客户将无法直接访问
php.ini
也没有访问权来修改Web服务器设置(例如Zend扩展名)。
How do I solve this in code? 如何在代码中解决这个问题? Is there a workaround?
有解决方法吗? Or is there an alternative to using
DOMDocument
? 还是有使用
DOMDocument
的替代方法?
You could try SimpleXML , as an alternative to DOMDocument. 您可以尝试SimpleXML ,以替代DOMDocument。 It should work out-of-the-box on all PHP5 installations.
它可以在所有PHP5安装中立即使用。
For example, this should be pretty close to what your DOMDocument code was meant to do: 例如,这应该非常接近您的DOMDocument代码的意图:
<?php
// Load the string and create a SimpleXMLElement
$html_string = file_get_contents("data/csr.html");
$root = new SimpleXMLElement($html_string);
// Fetch all div, h2 and span values
$divs = $h2s = $spans = array();
foreach ($xml->div as $div) {
$divs[] = $div;
}
foreach ($xml->h2 as $h2) {
$h2s[] = $h2;
}
foreach ($xml->span as $span) {
$spans[] = $span;
}
// etc...
?>
Haven't tested it tho, so you may have to adapt it a bit. 尚未测试过,因此您可能需要稍作调整。
There are also a number of other alternatives to parse XML documents (and most valid HTML documents, by extension). 还有许多其他替代方法可用于解析XML文档(以及最有效的HTML文档,以扩展方式)。 See PHP: XML Manipulation .
参见PHP:XML操作 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.