php - count(): Parameter must be an array or an object that implements Countable - phpWord
Get the solution ↓↓↓I am trying to output html to word using phpWord. However, something is weird. It works fine for the following code:
$content = '';
$content .= '<table><tr><th>Header</th><td>Content</td></tr></table>';
$content .= '<ul><li>Bullet</li><ul><li>Bullet</li></ul></ul>';
$content .= '<ol><li>Bullet</li></ol>';
Html::addHtml($newSection, $content);
But does not work for this:
$content = '';
$content .= '<table><tr><th>Header</th><td>Content</td></tr></table>';
$content .= '<p>Bullet</p>';
$content .= '<p>Cat</p>';
Html::addHtml($newSection, $content);
and produces the error mentioned on the title.
UPDATE
This error is generated from this file: \vendor\phpoffice\phpword\src\PhpWord\Shared\Html.php
In this method:
private static function parseChildNodes($node, $element, $styles, $data)
{
if ('li' != $node->nodeName) {
$cNodes = $node->childNodes;
if (count($cNodes) > 0) {
foreach ($cNodes as $cNode) {
if ($element instanceof AbstractContainer) {
self::parseNode($cNode, $element, $styles, $data);
}
}
}
}
}
But it only happens when using the<p>
html tag and it's fine with all other tags.
I also came across this link: addHtml() does not support tags inside list tags. #521
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: dompdf image not found or type unknown
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.