i am writing a php code that displays text from a database.
how would i make the text auto break <br /> after a certain amount of chars?
please help asap. thanks
6
Contributors
7
Replies
1 Day
Discussion Span
2 Years Ago
Last Updated
8
Views
Related Article:need help searching a database in php
is a solved PHP discussion thread by luke noob that has 2 replies, was last updated 2 years ago and has been tagged with the keywords: database, mysql, php, query, search.
The last code i gave wraps nearest word to index 20 of the string
The following code will split the line and insert the break after the 20th character
<?php
$text = "lets have a look how many chars before this breaks the string and inputs a line break";
$newtext = chunk_split($text, 20, "<br />\n");
echo $text."<br/>";
echo $newtext;
?>
OUTPUT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body
lets have a look how many chars before this breaks the string and inputs a line break<br/>
lets have a look how<br />
many chars before t<br />
his breaks the strin<br />
g and inputs a line <br />
break<br />
</body>
</html>