Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > PHP comments not working right

PHP comments not working right
Thread Tools
Junior Member
Join Date: May 2000
Status: Offline
Reply With Quote
Jun 14, 2001, 03:01 AM
 
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
Reply With Quote
Jun 14, 2001, 04:51 AM
 
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
     
sprynmr  (op)
Junior Member
Join Date: May 2000
Status: Offline
Reply With Quote
Jun 14, 2001, 10:12 AM
 
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
Reply With Quote
Jun 14, 2001, 10:33 AM
 
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>&lt;?php
<font color = brown>//<font color = green>this</font> is a comment</font>

echo <font color = red>"This is a test"</font>;
?&gt;
</font>[/code]
     
sprynmr  (op)
Junior Member
Join Date: May 2000
Status: Offline
Reply With Quote
Jun 14, 2001, 11:11 AM
 
Yep I did. For instance

&lt;?php
$holder = "user";
$$holder = "bob";
<font color = red>
//This comment screws up my output
#So does this comment
</font>
print "$user&lt;br&gt;";
print $$holder;
print "&lt;br&gt;";
print "${$holder}&lt;br&gt;";
print "${'user'}&lt;br&gt;"
?&gt;

Whereas

&lt;?php
$holder = "user";
$$holder = "bob";
<font color = red>
/* This comment doesn't screw it up
*/
</font>
print "$user&lt;br&gt;";
print $$holder;
print "&lt;br&gt;";
print "${$holder}&lt;br&gt;";
print "${'user'}&lt;br&gt;"
?&gt;

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
Reply With Quote
Jun 14, 2001, 06:05 PM
 
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.
     
sprynmr  (op)
Junior Member
Join Date: May 2000
Status: Offline
Reply With Quote
Jun 14, 2001, 07:15 PM
 
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
     
sprynmr  (op)
Junior Member
Join Date: May 2000
Status: Offline
Reply With Quote
Jun 14, 2001, 07:40 PM
 
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&gt;y){\r
echo "hellow";\r
}\r

will be seen by php as:
if(x&gt;y){ echo "hellow;}
Which is a valid statement. But if you do:

if(x&gt;y){\r
// say hellow \r
echo "hellow";\r
}\r

which will be seen by php as:
if(x&gt;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
Reply With Quote
Jun 15, 2001, 12:19 PM
 
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)?
     
sprynmr  (op)
Junior Member
Join Date: May 2000
Status: Offline
Reply With Quote
Jun 15, 2001, 01:00 PM
 
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
Reply With Quote
Jun 15, 2001, 04:38 PM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:33 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2