开发者

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting T_STRING or T_VARIABLE or '{' or '$' [closed]

开发者 https://www.devze.com 2023-02-08 11:42 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消