Forum


Replies: 2   Views: 3742
Array to string error in tutorial
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by kshaikh  · 24-07-2013 - 06:41

Hi,

I was trying to run the following code from tutorial:

require_once '../phpdocx_community/classes/CreateDocx.inc';

$docx = new CreateDocx();
$text = array();
$text[] =
array(
'text' => 'I am going to write'
);
$text[] =
array(
'text' => ' Hello World!',
'b' => 'on'
);

$text[] =
array(
'text' => ' using bold characters.'
);
$docx->addText($text);
$docx->createDocx('../word_documents/hello_world_2');
?>

and ran into the following error:

Warning: htmlspecialchars() expects parameter 1 to be string, array given in C:\xampp\htdocs\phpdocx_community\classes\CreateText.inc on line 576

It looks like the function addText is unable to use $text as an input argument since it is an array. Did anyone run into this issue? I tried to convert the array into a string by using implode method but it didn't print the value as expected. Instead, it simply printed "ArrayArrayArray".

Please advise.

Thanks,
Kamal