Reputation: 657
I am trying to break a line after 20 characters which I am displaying from mysql database but it is not breaking anything.
what I am getting
verylooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong
what I need
verylooooooooooooooo
oooooooooooooooooooo
<?php
$mydb = new mysqli('localhost', 'root', '', 'test');
$sql = "SELECT * FROM test order by id DESC ";
$result = $mydb->query($sql);
if (!$result) {
echo $mydb->error;
}
?>
<html>
<body>
<div>
<?php
while( $row = $result->fetch_assoc() ){
echo "<div class='Dtitle'>".wordwrap($row['title'], 20, "<br />\n")."</div>";
}
$mydb->close ();
?>
</div>
Upvotes: 0
Views: 807
Reputation:
by default wordwrap does not split words you need to add true as a parameter to the end in order to split words - see the manual page for more
echo "<div class='Dtitle'>".wordwrap($row['title'], 20, "<br />\n",true)."</div>";
Upvotes: 0
Reputation:
You're missing the cut
argument to wordwrap.
Try:
echo "<div class='Dtitle'>".wordwrap($row['title'], 20, "<br />\n", true)."</div>";
^^^^
The PHP reference for wordwrap is here
Upvotes: 1