?

Log in

No account? Create an account
entries friends calendar profile Previous Previous Next Next
WTF... - IBNeko's Journal-Nyo~!
ibneko
ibneko
WTF...
Why does my server not like:

if (isset($_POST['url'])) {
#clean URL
print $_POST['url'];

    /*
$out = escapeshellarg("addblog-test.pl $url");
print $out;
*/
}

if ($errors){
print "
$errors
";
}

(it gives me an error:
Parse error: syntax error, unexpected '}' in /home/uvemympn/public_html/dev/addblog.php on line 16, which line 16 is the last line.)

Yet it's perfectly fine if I take out the comments?
if (isset($_POST['url'])) {
#clean URL
print $_POST['url'];
}

if ($errors){
print "
$errors
";
}


I don't get it. I really don't. I even tried different ways of commenting... # and // both...

Tags:

3 happy kittens | Leave catnip
Comments
fbartho From: fbartho Date: February 14th, 2007 07:28 pm (UTC) (Link)
eek... It looks like php but it hurts my eyes!

Simple guidelines I would use:
- use // and /* comments not # (stylistic choice on my part
- don't make strings span newlines unless you have to.
- don't embed variables in strings "start $out end" vs "start ".$start." end", it usually works but sometimes it doesn't.
- I like to use echo instead of print, but that's just because I like being reminded I'm doing php and not C
- use proper indentation always, just for shits and giggles

In any case I copy pasted the corrupt code from my browser view of your page and it processed happily on my server.
ibneko From: ibneko Date: February 14th, 2007 08:00 pm (UTC) (Link)
-# is comments in perl (// and /* fail, I believe), and since that's the last language I'd been coding in... :: shrugs::
-Embedded variables in strings sometimes doesn't work? In perl, "out=$out" will cause the value of $out to be uh.. embedded, while 'out=$out' will return literally "out=$out". I've been presuming PHP is the same.
-Hm, I believe echo vs. print is just a stylistic choice. I think one might be slightly faster, although I may be mistaken.
-Eh, yeah, I do use proper indentation (4 spaces per tab, tabbing everything inside curly brackets. And I follow (Java?) suggestions of double-tabbing a hard-wrapped line of code. I just didn't bother fixing the spaces when I copied it over to livejournal - despite the fact that it would be just a s/ / /g replacement.

Huh. Wonder if it's a problem with totalchoicehosting's server... Buggers.
fbartho From: fbartho Date: February 15th, 2007 03:44 am (UTC) (Link)
According to Macromedia Dreamweaver, # // and /* are valid php comments. As for php variables in strings it will embed variables values if it notices the variable in the string... however it has trouble if you don't have spaces around the variable name and so occasionally it misses the variable and just embeds the dollar sign name.... unless you explicitly use the concatenate operator (.)
Like I said, arbitrary choice on echo. And I figured the indentation self died... next time copy paste the code into a <pre></pre> block. I do that most of the time for code. I personally like tab-character indentation because then one keypress = 1 unit of operation.
3 happy kittens | Leave catnip