Jump to content

wordwrap()


AV1611

Recommended Posts

I want to display a data field that is longtext, and I want to display it's contents in a <td>.  I want the text to wrap every 150 characters, but not to split on a word.  if a word is present, split on the last space before the 150 mark.

 

Am I asking to much?

Link to comment
Share on other sites

fair enough.

 

Let me change the question then...

 

I have a datafield that was imported to mysql from filemaker (Mac).

 

in some of the datafields there are some linefeeds (cr, \n, or whatever) that show up as little boxes when I use a textarea to display the field.  I don't want to change the data in the table as they will do imports/updates and the problem will still be there. 

 

How do I get the little boxes to be normal linefeeds so I can display them in the textarea correctly?

 

This doesn't work:

$line=str_replace('','\n',$row[6]);

it only gives \n in the HTML, as opposed to doing a linefeed in the textarea

 

Do I use implode? How?

 

HELP!

Link to comment
Share on other sites

This seems to work.

 

Any suggestions on how to make it "easier"?

 

Thanks!

 

$line=str_replace('','<br/>',$row[6]);
$line=str_replace('','<br/>',$line);
$line=nl2br($line);
$line=str_replace('<br />','<br/>',$line);
$lines=explode('<br/>',$line);
$i=count($lines);
$c=0;
echo "<tr><td class='padded'>Detailed Instructions:</td><td class='padded'>";
while($c < $i) {
	echo wordwrap($lines[$c],70,"<br/>");
	echo "<br/>";
	$c++;
	}
echo "</td></tr>";

Link to comment
Share on other sites

Can you please upload a text file with some of the text in question?

 

I think there is some unnecessary steps in your code. You would need to inspect the value of the text after each command to verify. But, here are my thoughts:

 

The first two lines are apparently to replace some of the "invalid" characters with a break. Does nl2br not take care of those already?

 

You are replacing the characters with "[br]", but then nl2br uses "{br /}" and then you are replacing that with "{br}". Just use "{br /}" as it is the proper usage.

 

Why are you exploding the text based upon "{br/}" and then echoing out each piece with a "{br/}" at the end.

 

Assuming you need those first two lines, try this:

 

$line=str_replace(' ','<br />',$row[6]);
$line=str_replace(' ','<br />',$line);
$line=nl2br($text);
echo "<tr><td class='padded'>Detailed Instructions:</td><td class='padded'>";
	echo wordwrap($line,70,"<br />");
echo "</td></tr>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.