We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,453 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

auto <br />

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
tcollins412
Junior Poster
139 posts since Dec 2010
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 0

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
Skill Endorsements: 0

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, "<br />\n");

echo $newtext;
?>

N

nuttyniall
Newbie Poster
19 posts since Apr 2010
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 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

rajvinoth
Newbie Poster
3 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

[B]nl2br()[/B]

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
Skill Endorsements: 0

Simply use <br> tag in php code. For example, $myvar .= $Row.'<br>';

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

none of those are working

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

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>
nuttyniall
Newbie Poster
19 posts since Apr 2010
Reputation Points: 10
Solved Threads: 3
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0813 seconds using 2.75MB