Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '{' or '$' [closed]
From this Simple Dom Site
if(isset($html->'div#sidebar'))
{
$sidebarFile = 'D:\xampp\htdocs\final\wordpress\sidebar.开发者_如何学Pythonphp';
$openSidebarFile = fopen($sidebarFile,'a');
foreach($html->find('div#sidebar')) as $e)
{
$html ->find('div[id=sidebar]', 0) -> innertext;
$inputSidebar = $e->outertext;
fwrite($openSidebarFile, "\n" .inputSidebar "\n");
}
}
From the documentation: it says:
// Determine whether a attribute exist?
if(isset($e->href))
echo 'href exist!';
There are a few issues here I'll just correct them inline:
if($html->find('div#sidebar'))
{
$sidebarFile = 'D:\xampp\htdocs\final\wordpress\sidebar.php';
$openSidebarFile = fopen($sidebarFile,'a');
foreach($html->find('div#sidebar') as $e)
{
$html ->find('div[id=sidebar]', 0) -> innertext;
$inputSidebar = $e->outertext;
fwrite($openSidebarFile, "\n" .inputSidebar "\n");
}
}
Now, what was changed? The first if
, and the foreach
. The if used the wrong function, and the wrong check for empty. The foreach had mismatched ()
braces.
Is $html->'div#sidebar'
really what you wanted? Where's find
?
Also, you can only use isset
with variables (or similar things such as array access), not function return values. Use empty
instead.
精彩评论