Jump to content

newline breaks


macdumbpling

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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.