Forum


Replies: 1   Views: 564
What is the correct syntax inside an array?
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 admin  · 24-05-2022 - 10:55

Hello,

Sorry, but we are not sure if we understand your question correctly.

In your code you are adding a new list with [$name, 'word'] in the second level and 'Example text.' in the first level.

If you use:

$myList = array(
    $name, 'word', 'Example text.',
);

all elements will be in the same level (first level in this case).

Please check the following sample available in all packages (Core/addList/sample_3.php) that illustrates a complex list applying styles using WordFragments:

// prepare some formatted text for insertion in the list
$textData = new WordFragment($docx);
$text = array();
$text[] = array('text' => 'We insert some ');
$text[] = array('text' => 'bold text', 'bold' => true);
$textData->addText($text);

// and also some simple HTML to illustrate the fexibility of the method
$htmlData = new WordFragment($docx);
$html = '<i>Some HTML code</i> with a <a href="http://www.phpdocx.com">link</a>';
$htmlData->embedHTML($html);

$itemList= array(
    'In this example we use a custom list (val = 5) that comes bundled with the default PHPdocX template.',
    array(
        $textData,
        'Line B',
        'Line C'
    ),
    $htmlData,
    'Line 3',
);

// set the style type to 5: other predefined Word list style
$docx->addList($itemList, 5);

If you send to contact[at]phpdocx.com the DOCX output you get now and the DOCX output you want to get after updating the same DOCX manually using MS Word or any other DOCX program we'll check it.

Regards.