Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to break a text into the next line in php?

Tags:

html

php

i have this project which is blog type where I pull posts submitted from the server. The problem is that when the post is echo(ed) the text goes all in one line , how do I make it go to the next line after certain length?

Here is the code where the text is being posted

$postpost = $result["post_user"];
echo " <b>name</b> = " .$result["username"] ."<br>";
echo " <b>post</b> = " .$result["post"] . "<br>";
echo " <b>date</b> = ".$date["date"]. " 
<br><br>----------------------<br><br>";

and here is the output problem enter image description here

like image 477
sam Avatar asked Nov 29 '22 18:11

sam


1 Answers

Use wordwrap() :

// the 80 is the number of characters after which to break:
echo " <b>post</b> = " . wordwrap($result["post"], 80, '<br>') . '<br>';

You may also be interested in nl2br().

like image 117
artlung Avatar answered Dec 01 '22 07:12

artlung