AV1611 Posted June 8, 2007 Share Posted June 8, 2007 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 https://forums.phpfreaks.com/topic/54783-wordwrap/ Share on other sites More sharing options...
Dragen Posted June 8, 2007 Share Posted June 8, 2007 yes Link to comment https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-270900 Share on other sites More sharing options...
AV1611 Posted June 8, 2007 Author Share Posted June 8, 2007 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 More sharing options...
Psycho Posted June 8, 2007 Share Posted June 8, 2007 Try this: echo wordwrap(nl2br($text), 150, "<br />"); If that doesn't work, please post some of the text that you are working with. Link to comment https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-270919 Share on other sites More sharing options...
Dragen Posted June 8, 2007 Share Posted June 8, 2007 try: $line=str_replace('', '<br />', $row[6]); Link to comment https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-270922 Share on other sites More sharing options...
AV1611 Posted June 8, 2007 Author Share Posted June 8, 2007 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 More sharing options...
cammac Posted June 8, 2007 Share Posted June 8, 2007 maybe this helps: wordwrap($string,150,"\n",true) Link to comment https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-270942 Share on other sites More sharing options...
chigley Posted June 8, 2007 Share Posted June 8, 2007 $line=str_replace('','<br/>',$row[6]); $line=str_replace('','<br/>',$line); What's the use of the second line there? Link to comment https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-270945 Share on other sites More sharing options...
AV1611 Posted June 8, 2007 Author Share Posted June 8, 2007 both invalid characters are in the database. It was a csv import from a filemaker database (Mac) Link to comment https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-270985 Share on other sites More sharing options...
chigley Posted June 8, 2007 Share Posted June 8, 2007 Sorry, in the [ code ] tags the characters weren't displayed! Link to comment https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-270991 Share on other sites More sharing options...
Psycho Posted June 8, 2007 Share Posted June 8, 2007 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 More sharing options...
AV1611 Posted June 10, 2007 Author Share Posted June 10, 2007 Sorry if the code is a little bloated... It's from working around m$ stuff too much I do the explode to make the wrap work right... at least that was the though Link to comment https://forums.phpfreaks.com/topic/54783-wordwrap/#findComment-271624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.