stuffradio Posted July 24, 2009 Share Posted July 24, 2009 I have a PHP string that I get from a database. What I need to do is echo this in Javascript. How can I do something like document.writeln or document.write something that has multiple lines? Link to comment https://forums.phpfreaks.com/topic/167225-multiple-lines/ Share on other sites More sharing options...
Third_Degree Posted July 24, 2009 Share Posted July 24, 2009 str_replace( "\r\n", "\\n", $content ); Link to comment https://forums.phpfreaks.com/topic/167225-multiple-lines/#findComment-881709 Share on other sites More sharing options...
stuffradio Posted July 24, 2009 Author Share Posted July 24, 2009 Let me rephrase my question. In Javascript, if you use document.writeln() or document.write()... you can only have one line written. How can I use Javascript to output mutliple lines without breaking. Link to comment https://forums.phpfreaks.com/topic/167225-multiple-lines/#findComment-881714 Share on other sites More sharing options...
Third_Degree Posted July 24, 2009 Share Posted July 24, 2009 let me rephrase my answer str_replace( "\r\n", "\\n", $content ); Ok, ok, I'll elaborate. multiple lines in javascript look like document.write('Hello\nThis is the Second Line'); So if you have a bunch of content generated by a php page, this is what you'd have to do: <?php $content = "hello this is the second line."; $content = str_replace( "\r\n", "\\n", $content ); print ' <script type="text/javascript"> document.write("' . $content . '"); </script>'; ?> Link to comment https://forums.phpfreaks.com/topic/167225-multiple-lines/#findComment-881717 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.