Jump to content

Archived

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

macdumbpling

newline breaks

Recommended Posts

I currently have a working event calendar that has a javascript popup div when you mouseover the title of an event. A javascript function call includes php variables:
[code]ShowInfo('$event[location]<br />$event[date]<br />$event[time] [$event[duration] $event[durLabel]]<br />$event[descrip]')[/code]
....you might notice that this script in itself would not work, it's just an example of passing my php variables into a javascript function). The problem with this is $event['descrip'] is a text box field from a form and can accept line breaks (in windows, the characters \r\n are line breaks, if you're unfamiliar). The problem lies when the html/javascript is sent to the browser and there is a line break in the $event['descrip'] variable. The code will show up like this:
[code]1 | ShowInfo('1st Floor Conference Room<br />2006-07-09<br />9:30 am [30 min]<br />Topics include:
2 | Inventory, Lunch schedules, etc.')[/code]
The javascript function is broken by the \r\n line break, causing an error on that event popup.

If anybody can point me in the appropriate direction to correct this quark, I'd be most appreciative! I've currently tried utf8_encode and utf8_decode (because I wasn't sure which it would be) and replacing the '\r\n' using str_replace() but that didn't work. I'm out of ideas and I don't even know where to begin, now.

Thank you in advance!
-Kevin

Share this post


Link to post
Share on other sites
To strip any new line chars use this:
[code]str_replace(array("\r", "\n"), "", $event[descrip])[/code]It is very important that you use double quotes when dealing with whitespace chars otherwise PHP will treat them as normal characters if you are using single quotes.

Share this post


Link to post
Share on other sites
YAY! YAY! YAY! There was that and then the addslashes() that I needed to add to escape " ' " and now it works wonderfully!

Thank you so much, wildteen88!

Share this post


Link to post
Share on other sites

×

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.