Jump to content

wordwrap help


scheibyem

Recommended Posts

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

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!  :wtf:

 

Any ideas??

Link to comment
https://forums.phpfreaks.com/topic/190026-wordwrap-help/#findComment-1002693
Share on other sites

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

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.