scheibyem Posted January 27, 2010 Share Posted January 27, 2010 Hi, I thought this would be a pretty simple thing to do, but I'm really having problems getting this wordwrap function to work. I'm trying to get the word wrap function to work. I'm retrieving data from a mySQL database. The data has been base64_encoded $wrapthis = base64_decode($data); $output = wordwrap($wrapthis, 80, "<br />\n"); I'm putting the $output into a html table. $wrapthis returns the data in the right text format however the wordwrap doesn't work. I'm thinking maybe the wordwrap function isn't recognizing the whitespaces between the words when they come out of a base64_decode?? What am I doing wrong??? Help! Link to comment https://forums.phpfreaks.com/topic/190026-wordwrap-help/ Share on other sites More sharing options...
JAY6390 Posted January 27, 2010 Share Posted January 27, 2010 That is odd. Try this instead $wrapthis = base64_decode($data); $output = nl2br(wordwrap($wrapthis, 80)); Link to comment https://forums.phpfreaks.com/topic/190026-wordwrap-help/#findComment-1002562 Share on other sites More sharing options...
scheibyem Posted January 27, 2010 Author Share Posted January 27, 2010 Nope...doesn't work. I forgot to mention that I actually have a nl2br when I'm inserting it in the database so the code looks like this: $64encoded = base64_encode(nl2br($somestr)); I tried however to just run the whole thing without inserting it in the database like this: $64encoded = base64_encode(nl2br($somestr)); $wrapthis = base64_decode($64encoded); $output = wordwrap($wrapthis, 80, "<br />\n"); And in this instance the wordwrap works so the output is wrapped! Any ideas?? Link to comment https://forums.phpfreaks.com/topic/190026-wordwrap-help/#findComment-1002693 Share on other sites More sharing options...
JAY6390 Posted January 28, 2010 Share Posted January 28, 2010 Ah, you need to do any wordwrap BEFORE using the base64_encode on the string, as that converts the whole string into one long string of numbers and letters only (and the = sign) so it can't wrap it Link to comment https://forums.phpfreaks.com/topic/190026-wordwrap-help/#findComment-1002777 Share on other sites More sharing options...
scheibyem Posted January 28, 2010 Author Share Posted January 28, 2010 But I'm wrapping after i do base64_decode. So the string has presumably already been converted back to the original string. Anyway, I found out what was happening. When I insert into the database I changed whitespaces for non-breaking-space so that is why the wordwrap couldn't work. It is kinda working now however, now there is another problem. I'm using this code wordwrap($wrapthis, 80, "<br />\n"); I ran this on a some text from cnn.com and this it what it gives me in the html source: What this device does is extraordinary," Jobs said. "It is the best browsing<br /> experience you've ever had. ... It's unbelievably great ... way better than a<br /> laptop. Way better than a smartphone."<br /> The computer will act as a sort of<br /> missing link between the two. The model Jobs demonstrated at an invitation-only<br /> event in San Francisco operated without a hardware keyboard, with Jobs typing on<br /> what he described as a nearly full-size touchscreen keyboard.<br /> "It's a<br /> dream to type on," he said.<br /> It has a</td> So the wrap kinda works but some line are much smaller than others even though they are no where near the limit. Any help would be appreciated! Link to comment https://forums.phpfreaks.com/topic/190026-wordwrap-help/#findComment-1002813 Share on other sites More sharing options...
JAY6390 Posted January 28, 2010 Share Posted January 28, 2010 replace all new lines with a space, and then run the wordwrap on it Link to comment https://forums.phpfreaks.com/topic/190026-wordwrap-help/#findComment-1002814 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.