Forum


Replies: 1   Views: 80
What is the correct syntax inside an array?

Posted by martinsimmermann  · 24-05-2022 - 10:29

How do I insert a variable (I don't know if the term is correct) to an list array so that the text inside the array continues from the same line. 

What should be the correct syntax for the $name inside the array?

$docx->createListStyle('Latin', $numberatsioonDisain);

$name = $_POST['name']; // Value comes from HTML form

$myList = array(
    [$name, 'word'], // Value is correct, but "Example text" starts from a new line (with a new list number). But I want the second word to continue from the same line. 
    'Example text.');

$docx->addList($myList, 'Latin');

 

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 lists 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.