macdumbpling Posted March 31, 2006 Share Posted March 31, 2006 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 Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted March 31, 2006 Share Posted March 31, 2006 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. Quote Link to comment Share on other sites More sharing options...
macdumbpling Posted March 31, 2006 Author Share Posted March 31, 2006 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! 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.