PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 10, 2022

[FIXED] How to add a textbreak in phpword?

 November 10, 2022     php, phpword     No comments   

Issue

I use the "phpword" class to generate a .doc file, but i have the problem:

how to add a line break for this problem?, so for example I have the following text:

Code (in a variable):

"This is
a text
With line break"

Now if we enter that into the word document...will display this:

"This is a text With line break."

how can i do this? i want the text in the word document with this style:

This is
a text
With line break

Thanks!


Solution

This is not possible with phpword. You have to split the string in lines and use addTextBreak.

<?php
$text = "This is
a text
With line break";

$lines = explode("\n", $text);

foreach ($lines as $line) {
    $doc->addText($line);
    $doc->addTextBreak();
}


Answered By - tino.codes
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing