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? Quote Link to comment Share on other sites More sharing options...
Dragen Posted June 8, 2007 Share Posted June 8, 2007 yes Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Dragen Posted June 8, 2007 Share Posted June 8, 2007 try: $line=str_replace('', '<br />', $row[6]); Quote Link to comment 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>"; Quote Link to comment 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) Quote Link to comment 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? Quote Link to comment 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) Quote Link to comment 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! Quote Link to comment 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>"; Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.