ShadowMage Posted November 8, 2010 Share Posted November 8, 2010 Javascript also does not support multi-line strings, so you may want to replace line break characters with spaces.Or use a '+'This works:alert("A multiline"+"string."); Link to comment Share on other sites More sharing options...
justsomeguy Posted November 8, 2010 Share Posted November 8, 2010 Right, you can also replace a line break with a close quote, plus, line break, and opening quote. Link to comment Share on other sites More sharing options...
ShadowMage Posted November 8, 2010 Share Posted November 8, 2010 Right, you can also replace a line break with a close quote, plus, line break, and opening quote. When you put it that way I can see why you suggested spaces. Much simpler. Link to comment Share on other sites More sharing options...
Hooch Posted November 9, 2010 Author Share Posted November 9, 2010 str_replace("<br />", " ", $description);str_replace("<br>", " ", $description); I am absolutely stumped on your explanation for escaping the double quotes.Could I trouble you to show me? I do prefer to learn this and thank you so much for taking the time to try and teach me but I was trying to have this code done today.Thank you (all) for all your help so far. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 9, 2010 Share Posted November 9, 2010 You can probably just remove the call to addslashes, the 3 calls to str_replace are escaping everything so addslashes is going to escape everything again. Link to comment Share on other sites More sharing options...
Hooch Posted November 9, 2010 Author Share Posted November 9, 2010 Removing the addslashes = onmouseover="document.getElementById('myText').firstChild.data='<span style=\"font-size: xx-large;\"><span style=\"color: rgb(255, 153, 0);\"><span style=\"font-weight: bold;\">A</span></span></span><span style=\"font-size: x-large;\"><span style=\"font-weight: bold;\">rt portfolio</span></span><span style=\"font-weight: bold;\"><br /></span>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer tristique turpis justo, in porttitor urna. Quisque erat tortor, consequat non lacinia sed, laoreet semper elit. Proin sed ante at ipsum egestas consectetur. Suspendisse dignissim enim id arcu aliquet vitae lacinia dolor dignissim. Vivamus sem mauris, bibendum id mollis a, tincidunt id ligula. Etiam ultrices mauris id ligula porta eleifend. Nulla euismod mi sit amet mi ornare et tempor magna mattis. Integer quis erat leo. Quisque porta, odio nec venenatis congue, urna dui mollis augue, a pretium turpis dui eget nunc. Donec porta varius diam eu fermentum. Praesent nibh ipsum, pulvinar vel eleifend at, pretium eget lectus. Sed pretium, dolor at convallis sollicitudin, purus metus tempus nunc, sit amet pellentesque purus lorem id sapien. Ut sed commodo velit. Praesent eu lorem massa. Sed eleifend lorem in diam iaculis sit amet mattis odio varius. Proin venenatis eros sit amet dolor pharetra vel laoreet leo dapibus. Ut lectus quam, congue ac tristique vitae, porta non tortor. Suspendisse potenti. In egestas cursus nulla et suscipit. Mauris posuere felis quis nunc consequat sit amet pulvinar orci semper.Suspendisse potenti. Duis auctor rutrum ante vel mattis. Aliquam quis nunc arcu. Suspendisse scelerisque massa id sem luctus vulputate mollis erat feugiat. Phasellus metus neque, venenatis at semper vel, malesuada vel velit. Donec pellentesque ultrices mauris, porta condimentum enim dignissim et. In posuere luctus dolor quis consectetur. Duis eros mi, lobortis nec egestas ac, ullamcorper ut justo. Donec viverra auctor venenatis. Suspendisse potenti. Cras aliquet lobortis luctus. Quisque lobortis est nec leo lacinia quis vulputate erat sagittis. Morbi et nisl enim. Quisque fringilla feugiat arcu, nec luctus tellus faucibus sed. Proin convallis nunc eu mi bibendum sed congue justo laoreet.Quisque consequat pellentesque metus, convallis dictum purus tristique pulvinar. Suspendisse purus felis, euismod in lacinia in, vestibulum a urna. Quisque tristique mi eu ligula viverra faucibus. Etiam neque dui, auctor nec dignissim a, venenatis ac erat. Maecenas leo ipsum, euismod sit amet rutrum ut, convallis in sapien. Proin est eros, fermentum lobortis mollis tempor, pretium quis metus. Duis id nibh quis augue euismod condimentum. Nam hendrerit accumsan eros a aliquet. Proin ac nisi diam, at euismod mi. Proin et justo non velit porta iaculis ac sit amet nunc. Maecenas blandit mauris eget justo porttitor pellentesque quis ut mauris. Morbi felis augue, luctus sit amet ullamcorper posuere, sagittis sed lacus.<span style=\"font-weight: bold;\"><br /><br /></span>';return true;" What I find weird here is there's still the line break showing. I did add the code to replace line breaks with a space. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 9, 2010 Share Posted November 9, 2010 Make sure you're replacing both \r and \n. It's probably enough to replace each one individually, but if you use this you can replace "\r\n" as a sequence first, which is the Windows line ending, then "\r", which is for Mac, then "\n", which is for Linux:str_replace("\n", str_replace("\r", str_replace("\r\n", $text)));It looks like the documentation for str_replace specifies that the replacements get made first to last if you're replacing arrays, so since the order matters for you and str_replace respects the order then you can simplify with a couple of arrays: $search = array("\\", "'", "\"", "\r\n", "\r", "\n");$replace = array("\\\\", "\\'", "\\\"", " ", " ", " ");$description = str_replace($search, $replace, $description); That's probably easier to read than a bunch of nested str_replace calls. Link to comment Share on other sites More sharing options...
Hooch Posted November 9, 2010 Author Share Posted November 9, 2010 Thanks Guy.Still showing the same results.Here's my code $description = $r2['description'];$search = array("\\", "'", "\"", "\r\n", "\r", "\n");$replace = array("\\\\", "\\'", "\\\"", " ", " ", " "); $description = str_replace($search, $replace, $description); echo '<a id="example4" href="portfolio.php?PGid=' . $r2['level1'] . '&p=1" onmouseover="document.getElementById(\'myText\').firstChild.data=\'' . $description . '\';return true;" title="' . $r2['item_name']. '" border="0"><img alt="" src="' . $image . '?x=' . $stopCacheProb . '" height="' . $newHeight . '" width="' . $newWidth . '" class="portThumbs" /></a>'; And here's the output <a id="example4" href="portfolio.php?PGid=art&p=1" onmouseover="document.getElementById('myText').firstChild.data='<span style=\"font-size: xx-large;\"><span style=\"color: rgb(255, 153, 0);\"><span style=\"font-weight: bold;\">A</span></span></span><span style=\"font-size: x-large;\"><span style=\"font-weight: bold;\">rt portfolio</span></span><span style=\"font-weight: bold;\"><br /> </span> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer tristique turpis justo, in porttitor urna. Quisque erat tortor, consequat non lacinia sed, laoreet semper elit. Proin sed ante at ipsum egestas consectetur. Suspendisse dignissim enim id arcu aliquet vitae lacinia dolor dignissim. Vivamus sem mauris, bibendum id mollis a, tincidunt id ligula. Etiam ultrices mauris id ligula porta eleifend. Nulla euismod mi sit amet mi ornare et tempor magna mattis. Integer quis erat leo. Quisque porta, odio nec venenatis congue, urna dui mollis augue, a pretium turpis dui eget nunc. Donec porta varius diam eu fermentum. Praesent nibh ipsum, pulvinar vel eleifend at, pretium eget lectus. Sed pretium, dolor at convallis sollicitudin, purus metus tempus nunc, sit amet pellentesque purus lorem id sapien. Ut sed commodo velit. Praesent eu lorem massa. Sed eleifend lorem in diam iaculis sit amet mattis odio varius. Proin venenatis eros sit amet dolor pharetra vel laoreet leo dapibus. Ut lectus quam, congue ac tristique vitae, porta non tortor. Suspendisse potenti. In egestas cursus nulla et suscipit. Mauris posuere felis quis nunc consequat sit amet pulvinar orci semper. Suspendisse potenti. Duis auctor rutrum ante vel mattis. Aliquam quis nunc arcu. Suspendisse scelerisque massa id sem luctus vulputate mollis erat feugiat. Phasellus metus neque, venenatis at semper vel, malesuada vel velit. Donec pellentesque ultrices mauris, porta condimentum enim dignissim et. In posuere luctus dolor quis consectetur. Duis eros mi, lobortis nec egestas ac, ullamcorper ut justo. Donec viverra auctor venenatis. Suspendisse potenti. Cras aliquet lobortis luctus. Quisque lobortis est nec leo lacinia quis vulputate erat sagittis. Morbi et nisl enim. Quisque fringilla feugiat arcu, nec luctus tellus faucibus sed. Proin convallis nunc eu mi bibendum sed congue justo laoreet. Quisque consequat pellentesque metus, convallis dictum purus tristique pulvinar. Suspendisse purus felis, euismod in lacinia in, vestibulum a urna. Quisque tristique mi eu ligula viverra faucibus. Etiam neque dui, auctor nec dignissim a, venenatis ac erat. Maecenas leo ipsum, euismod sit amet rutrum ut, convallis in sapien. Proin est eros, fermentum lobortis mollis tempor, pretium quis metus. Duis id nibh quis augue euismod condimentum. Nam hendrerit accumsan eros a aliquet. Proin ac nisi diam, at euismod mi. Proin et justo non velit porta iaculis ac sit amet nunc. Maecenas blandit mauris eget justo porttitor pellentesque quis ut mauris. Morbi felis augue, luctus sit amet ullamcorper posuere, sagittis sed lacus. <span style=\"font-weight: bold;\"><br /> <br /> </span>';return true;" title="" border="0"><img alt="" src="images/galleries/art/main.jpg?x=1289308807" height="400" width="160" class="portThumbs" /></a> Thanks for the help so far.Am I correct in assuming we should not be seeing the slash before the double quotes in the output? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 9, 2010 Share Posted November 9, 2010 It looks like I misunderstood how escaping the quotes works in situations like this. You do need to use the character entity for a quote, ". You can probably use this: $search = array("'", "\"", "\r\n", "\r", "\n");$replace = array("\\'", """, " ", " ", " "); Link to comment Share on other sites More sharing options...
Hooch Posted November 9, 2010 Author Share Posted November 9, 2010 This seems to be closer. When I mouse over the images the text will appear whereit should but the text is outputted as " instead of the actual quote ( " ). Link to comment Share on other sites More sharing options...
justsomeguy Posted November 9, 2010 Share Posted November 9, 2010 I was trying it with innerHTML instead of data, data wasn't working for me. Link to comment Share on other sites More sharing options...
Hooch Posted November 10, 2010 Author Share Posted November 10, 2010 Here's a question.Is there another way to mouse over an image to show text elsewhere?Maybe an easier option? Link to comment Share on other sites More sharing options...
justsomeguy Posted November 10, 2010 Share Posted November 10, 2010 I guess you could output a function for each mouseover and then you wouldn't have to worry about escaping the double-quotes. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.