2017-09-27 19:29
浏览 166


I am using the following function as suggested by a friend here to get the innerHTML. While the function works fine and solves my purpose, it is showing syntax error in my IDE. I am not an expert in coding hence not able to figure out. Requesting help in correcting the code.

My code:


$body = $doc->getElementsByTagName('body')->item(0);

$content = implode(
    array_map([$doc, 'saveHTML'], iterator_to_array($body->childNodes))

echo $content;

My IDE is showing error on this line array_map([$doc, 'saveHTML'], iterator_to_array($body->childNodes))


I use Adome Dreamweaver CS6 as my code editor.

enter image description here

图片转代码服务由CSDN问答提供 功能建议

我正在使用朋友建议的以下函数来获取innerHTML。 虽然该函数工作正常并解决了我的目的,但它在我的IDE中显示语法错误。 我不是编码方面的专家,因此无法弄清楚。 请求帮助纠正代码。


  $ body = $ doc-&gt; getElementsByTagName('body') - &gt; item(0); 
 $ content = implode(
 array_map([$ doc,'saveHTML'],iterator_to_array  ($ body-&gt; childNodes))
echo $ content; 

我的IDE在此行显示错误 array_map( [$ doc,'saveHTML'],iterator_to_array($ body-&gt; childNodes))


我使用Adome Dreamweaver CS6作为我的代码编辑器。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douwen5924 2017-09-27 19:41

    The Dreamweaver CS6 PHP syntax version is 5.3. All 5.4 and later functions/syntax will not be available to it.


    Longer explanation for this specific example, shorthand arrays aren't allowed in your editor. If you want the editor to stop complaining you can swap to array() or upgrade to the CC version.

    This code will work fine if your actual server is running 5.4 or later.

    打赏 评论

相关推荐 更多相似问题