 |
 |
PHP comments not working right
|
 |
|
 |
|
Junior Member
Join Date: May 2000
Status:
Offline
|
|
I'm learning PHP on OSX right now. When I try and do a single line comment via the
//
or the
#
the PHP does not work correctly. It doesn't seem to see these as comments, and rather just prints them out. The longer comment thingy works
/*
*/
Note: This is all done in BBEdit, although that shouldn't matter.
Do I have to fix something in a PHP config file?
Little Help?
[ 06-14-2001: Message edited by: sprynmr ]
|
M. Robert Spryn
Grad Student
NYU Center for Advanced Digital Apps
sprynmr@mac.com
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Mar 2000
Location: ireland
Status:
Offline
|
|
the single line comment is a double slash "//". sorry if that'll double your workload.... but it works 
|
the original madra - airbrushed out of history in a stalinist manner!
madrasite - crap, junk and drivel
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2000
Status:
Offline
|
|
Doh. I meant to put that in the post. That's what I was using, not just the single slash, and it still wasn't reading it right.
None of my single line comments work. For some reason it tries to read them. I'm confused.
|
M. Robert Spryn
Grad Student
NYU Center for Advanced Digital Apps
sprynmr@mac.com
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Aug 1999
Status:
Offline
|
|
Make sure that your comments are within the PHP block like:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier><?php
<font color = brown>//<font color = green>this</font> is a comment</font>
echo <font color = red>"This is a test"</font>;
?>
</font>[/code]
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2000
Status:
Offline
|
|
Yep I did. For instance
<?php
$holder = "user";
$$holder = "bob";
<font color = red>
//This comment screws up my output
#So does this comment
</font>
print "$user<br>";
print $$holder;
print "<br>";
print "${$holder}<br>";
print "${'user'}<br>"
?>
Whereas
<?php
$holder = "user";
$$holder = "bob";
<font color = red>
/* This comment doesn't screw it up
*/
</font>
print "$user<br>";
print $$holder;
print "<br>";
print "${$holder}<br>";
print "${'user'}<br>"
?>
I'm running these scripts on my own server on OS X. I installed php 4.0.5 and the latest apache. I can't figure this one out for the life of me. They are just comments, they should work.
[ 06-14-2001: Message edited by: sprynmr ]
|
M. Robert Spryn
Grad Student
NYU Center for Advanced Digital Apps
sprynmr@mac.com
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Mar 2001
Status:
Offline
|
|
That's weird because the web hosting company that i'm having host my php site did the exact same thing! all of a sudden it printed out my //'s and gave me parse errors.
I took out the //'s and all was o.k. i have no clue why this happened. probably because someone did an upgrade to php and didn't tell us.
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2000
Status:
Offline
|
|
I am using PHP-4.0.5, which to my understanding was just released. i'm checking around for anyone else having the problem.
|
M. Robert Spryn
Grad Student
NYU Center for Advanced Digital Apps
sprynmr@mac.com
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2000
Status:
Offline
|
|
Ok, I found my answer on php-mailing list. This one guy was complaining of the same problems. Another user provided this answer. I tested it, and it is the fix. For some reason 4.0.5 changed things so newlines made by BBEdit aren't recognized correctly. Anyone know how to change the newline characters that BBEdit uses? I don't feel like using pico permanently.
From the mailing list:
As I said before, it is most likely due to the newlines that PHP can not
recognize. You do not see the newlines, so as far as you are concerned,
the code is totally valid. But this is not what PHP sees - PHP sees a
long string rather than multiple lines in your code because it treats a
single '\r' as a whitespace.. Try to replace all single '\r' in your
code with '\n' or '\r\n'. This sould be a simple script that does not
damage any of your scripts, can do that automatically, and should fix
the problem..
The problem usually comes from editing your code with different editors
- one uses '\r' as a newline, and the other - 'r\\n', for example. So
some of your code will be broken, and some - not.. To make things more
confusing, PHP allows you to have several statements on one line
(sometimes), so in some places '\r' will not break it while in some
other it will.. For example (I make newlines visible),
if(x>y){\r
echo "hellow";\r
}\r
will be seen by php as:
if(x>y){ echo "hellow;}
Which is a valid statement. But if you do:
if(x>y){\r
// say hellow \r
echo "hellow";\r
}\r
which will be seen by php as:
if(x>y){ // say hellow \r echo "hellow;}
Which is obviously broken. In fact, php should give you an error because
among other things you just commented out the closing curly bracket.
Now, if you used UNIX-style or DOS-style ('\n' or '\r\n') newlines
instead, everything would be fine
Bottom line: It is not a // comments problem, you do not have to switch
to /* */ comments, just take your hex editor, look at your source file
in hex (pay attention to newlines) and replace them with proper
newlines. That should fix that.
Take care,
Vlad
|
M. Robert Spryn
Grad Student
NYU Center for Advanced Digital Apps
sprynmr@mac.com
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Sep 2000
Location: Shallow Alto, CA
Status:
Offline
|
|
sprynmr,
does this still happen if you change the line endings in BBedit to Unix using the tiny page icon (or under options when saving)?
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: May 2000
Status:
Offline
|
|
Thanks very much! That was the preference I was looking for. This solves the aforementioned problem completely. For some reason as of php-4.0.5, Macintosh style line breaks are not recognized. Thus the php parser sees your file as ONE LONG LINE. So just change the default preference to save line breaks in unix style.
Originally posted by foamy:
<STRONG>sprynmr,
does this still happen if you change the line endings in BBedit to Unix using the tiny page icon (or under options when saving)?</STRONG>
|
M. Robert Spryn
Grad Student
NYU Center for Advanced Digital Apps
sprynmr@mac.com
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Sep 2000
Location: Shallow Alto, CA
Status:
Offline
|
|
Whew! I'm glad that was the problem. I use Unix linefeeds by default and have an earlier version of PHP installed so I couldn't replicate the problem.
I just redid an entire site in PHP and was getting really worried about uploading it to our ISP who's running 4.05.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|