Free Web Hosting Forum
(#1 (permalink))
Old
Junior Member
raineym is on a distinguished road
 
Posts: 3
Join Date: Jul 2008
Default [PHP] Not Reading Newlines - 07-22-2008, 06:56 PM

I have a site that I am transferring here and the code works perfectly on the other host, but when I transfer the code here, it does not recognize \n, \r, or \r\n in the PHP code to make the HTML code look nice.

I know the code is not wrong because its working perfectly on the other host.

I set up a test page to see if I was crazy, but it looks like I'm not: http://raineym.net63.net/test.php

Any help would be appreciated.

Last edited by raineym : 07-22-2008 at 07:04 PM.
Reply With Quote
(#2 (permalink))
Old
Darkerzx's Avatar
Junior Member
Darkerzx is on a distinguished road
 
Posts: 22
Join Date: Jun 2008
Default 07-22-2008, 08:48 PM

Try to use nl2br()

<?php
echo nl2br("hello\n world");
?>

It will output a <br /> tag.


My website -The free community

if (my_post_was_helpful == yes)
{
Karma me
}
else
{
Do nothing
}
Reply With Quote
(#3 (permalink))
Old
Junior Member
raineym is on a distinguished road
 
Posts: 3
Join Date: Jul 2008
Default 07-23-2008, 02:07 AM

I know the nl2br() PHP function. I have been programming in PHP for almost 7 years now.

Perhaps I need to explain it this way. What I'm trying to do is make where my HTML, when outputted by the PHP script, looks like this when you view the source:
Code:
<blockquote>
     <p>Hello, World!</p>
</blockquote>
Instead of like this when you view the source:
Code:
<blockquote><p>Hello, World!</p></blockquote>
Every time I put in \n, \r, or any combination of the two it just outputs the \n and/or \r as text to the browser.

The PHP script on test.php has the following line of code:
Code:
echo '<blockquote>\n     <p>One</p>\n     </blockquote>\n';
When you view the source of the page in the browser, it looks like this:
Code:
<blockquote>\n<p>One</p>\n</blockquote>\n
In addition, PHP functions like explode() and str_replace() don't even see the \n or \r in the strings passed to them and implode() just places the strings together with the \n and/or \r outputted to the browser as text.
Reply With Quote
(#4 (permalink))
Old
Darkerzx's Avatar
Junior Member
Darkerzx is on a distinguished road
 
Posts: 22
Join Date: Jun 2008
Default 07-23-2008, 03:08 AM

I found what the problem was you just need to replace the ' to "

ex:
PHP Code:
<?php
echo("<blockquote>\n <p>One</p>\n</blockquote>\n<blockquote>\n <p>Two</p>\n</blockquote>\n<blockquote>\n <p>Three</p>\n</blockquote>\n<blockquote>\n <p>Four</p>\r</blockquote>\r");
?>


My website -The free community

if (my_post_was_helpful == yes)
{
Karma me
}
else
{
Do nothing
}
Reply With Quote
(#5 (permalink))
Old
Junior Member
raineym is on a distinguished road
 
Posts: 3
Join Date: Jul 2008
Default 07-23-2008, 02:11 PM

That did it. Now I have to go through thousands on lines of code and fix all of that. Find >> Replace, here I come.

This is the first web host I've seen where the ' and " were not interchangable in PHP code.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0
vBulletin Skin developed by: vBStyles.com