Jump to content

wordwrap()


AV1611

Recommended Posts

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
https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-270915
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
https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-270936
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
https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-271027
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.