help with \n
Moderator: General Moderators
-
php12342005
- Forum Commoner
- Posts: 79
- Joined: Mon Mar 21, 2005 3:35 am
help with \n
followings are php code, error on line 3 because of the \n.
I can not understand that why \t is ok but \n is error?
headache for php.
(\n is for breaking a new line)
if(!$connect||!$selectdb)
{
$error= "Error: can not connect to database\n";//line 3
$error.="user:\t".$dbuser."<br>";
print '<script language="javascript">';
print 'alert("'.$error.'")';
print '</script>';
return false;
}
why and how?
thanks
I can not understand that why \t is ok but \n is error?
headache for php.
(\n is for breaking a new line)
if(!$connect||!$selectdb)
{
$error= "Error: can not connect to database\n";//line 3
$error.="user:\t".$dbuser."<br>";
print '<script language="javascript">';
print 'alert("'.$error.'")';
print '</script>';
return false;
}
why and how?
thanks
-
php12342005
- Forum Commoner
- Posts: 79
- Joined: Mon Mar 21, 2005 3:35 am
please excuse me as i only started this PHP stuff the other day but i think you will find your having and error on both lines BUT the results your getting are confusing....
Im guessing your commenting out the line you marked "line 3" ... in doing so the line is ignored and the one bellow it becomes line 3 (but your expecting it to still be line 4)?
To test this i made a simple php program:
ran it with an error on the 1st line... then commended out the 1st line and still got an error on the first line ...
Showing me the commenting means its ignored this is probably why the error on line 3 and 4 appear as both errors on line 3 as commenting out the current line 3 makes the current line 4 become line 3.
to fix it place the \n's and \t's outside html tags like so
Im guessing your commenting out the line you marked "line 3" ... in doing so the line is ignored and the one bellow it becomes line 3 (but your expecting it to still be line 4)?
To test this i made a simple php program:
Code: Select all
<?php
echo " Test \n";
echo " Test2 \t";
echo " Test3 \t";
?>Showing me the commenting means its ignored this is probably why the error on line 3 and 4 appear as both errors on line 3 as commenting out the current line 3 makes the current line 4 become line 3.
to fix it place the \n's and \t's outside html tags like so
Code: Select all
echo " <p>Test</p> \n";
echo " <p>Test2</p> \t";
echo " <p>Test3</p> \t";-
php12342005
- Forum Commoner
- Posts: 79
- Joined: Mon Mar 21, 2005 3:35 am
Re: help with \n
Code: Select all
if(!$connect||!$selectdb)
{
$error= "e;Error: can not connect to database\\n"e;;
$error.="e;user:\t"e;.$dbuser."e;<br>"e;;
print '<script language="e;javascript"e;>';
print 'alert("e;'.$error.'"e;)';
print '</script>';
return false;
}You want the the "\n" to end up inside the javascript, so that the javascript inserts a line break. You don't want PHP to replace the \n with a linebreak. Therefore you have to escape the slash, so that javascript see "\n".
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
php12342005 now I'm telling you! hawleyjr is right. Read how to post code and at the very least use
Code: Select all
tags. You have nearly 60 posts, I'd expect you to have got the message by now