954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

auto <br />

i am writing a php code that displays text from a database.
how would i make the text auto break [CODE]
/CODE] after a certain amount of chars?
please help asap. thanks

tcollins412
Junior Poster
139 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 


Can you give some example code for us to have an idea regarding your script?

lyrico
Junior Poster in Training
94 posts since Dec 2010
Reputation Points: 33
Solved Threads: 15
 

Hi
If its to format the output from the database would you not be better using css to wrap the text placed in a container??

You can wrap text using php using the following

<?php
$text = "The quick brown fox jumped over the lazy dog.";
$newtext = wordwrap($text, 20, "\n");

echo $newtext;
?>


N

nuttyniall
Newbie Poster
19 posts since Apr 2010
Reputation Points: 10
Solved Threads: 3
 

Hi,
You can use the given code for auto break.It will automatically add br tag to the string.
<?php $string = nl2br($string); ?>

The above code will help you

rajvinoth
Newbie Poster
3 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

Hi, You can use the given code for auto break.It will automatically add br tag to the string. <?php $string = nl2br($string); ?>

The above code will help you

YES I agree with you just simply call this function

<strong>nl2br()</strong>


it will make line breaks on your record to a new line.

kuink
Newbie Poster
9 posts since Jan 2011
Reputation Points: 10
Solved Threads: 1
 

Simply use
tag in php code. For example, $myvar .= $Row['fieldname'].'
';

johnsteve.bravo
Light Poster
39 posts since Jan 2011
Reputation Points: 11
Solved Threads: 6
 

none of those are working

tcollins412
Junior Poster
139 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
 

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, "\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 
 many chars before t 
his breaks the strin 
g and inputs a line  
break 

</body>

</html>
nuttyniall
Newbie Poster
19 posts since Apr 2010
Reputation Points: 10
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: