私はここで苦境に陥っています。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
ソースは次のとおりです。
<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>
オンラインでいくつかの調査を行った後、Zend拡張機能が原因である可能性があることがわかりました。これが私の Zend セットアップの外観です。
このプログラムは、Zend Scripting Language Engine を使用しています。 Zend Extension Manager v1.2.0、著作権 (c) 2003-2007、Zend Technologies による Zend Optimizer v3.3.3、著作権 (c) 1998-2007、Zend Technologies による
このコードをいくつかの新しい Windows システムでテストしましたが、すべて失敗しました。これにより、多くではないにしても、ほとんどのウェブホストが私が持っているものと同様の設定を使用している可能性があると私は信じています. php.ini
私が読んだ内容に基づく一般的な解決策は、Zend を無効にするか、ファイルの特定の領域をコメントアウトすることです。これは配布用のスクリプトの一部であるため、ほとんどの顧客は に直接アクセスしphp.ini
たり、Zend 拡張機能などの Web サーバー設定を変更するアクセス権を持っていません。
これをコードで解決するにはどうすればよいですか? 回避策はありますか? または、使用する代わりの方法はありDOMDocument
ますか?