|
7 Apr 2003, 23:27
|
#1
|
Born Sinful
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
|
Very basic PHP question...
I'm just starting to fiddle with PHP. I'm making a simple little script which reads news out of a text file and will (once i've got the basics sorted) lay it out in keeping with the rest of the site, thus saving me much messing about editing html tables.
I figured for something this simple it wasn't worth doing it in a database.
I have no experience of PHP except for what I've read and tried in the last 30 minutes but I do know C and C++ quite well.
Anyway, I've hit a problem at a basic point;
This works:
Code:
echo "<br>", fgets($handle,300) ;
This doesn't:
Code:
echo("<br>", fgets($handle,300));
Can anyone tell me why?
I know echo doesn't need brackets and I know it isn't actually a function, but I'd like to be able to reference it as one for the sake of making my code more readable to myself and it supports the ability to anyway.
I can happilly do the above using brackets if I write it as two seperate echo statements, so what's up that I'm missing here?
Thanks.
__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
|
|
|
7 Apr 2003, 23:46
|
#2
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Re: Very basic PHP question...
What sort of reason are you looking for? PHP is not a designed language.
Code:
echo "<br>", fgets($handle,300) ;
zend_language_scanner.y has bits like this:
echo statment: T_ECHO echo_expr_list ';'
echo_expr_list:
echo_expr_list ',' expr
| expr
;
An expresion looks like "<br>" or ("<br>") or fgets($handle,300) or (fgets($handle,300)), but not like ("<br>", fgets($handle,300)).
__________________
#linux
|
|
|
7 Apr 2003, 23:51
|
#3
|
Born Sinful
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
|
Oh well, looks like I live with it then.
__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
|
|
|
8 Apr 2003, 00:00
|
#4
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
You really don't like using echo("a". "b");?
You could use function my_echo() { $args=func_get_args(); echo join("",$args); }
Or you could use a decent language like CLisp or Erlang, or even Python/Ruby/Perl.
|
|
|
8 Apr 2003, 00:13
|
#5
|
Born Sinful
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
|
Forgive me here - why does using "." work?
I'm really too tired to understand the answer so I'll look tomorrow morning.
I would learn perl if I could be bothered but I don't have much free time at the moment and I allready have most of the knowledge I need (ie. the C/C++ and some basic MySQL) to get going in PHP very quickly.
__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
|
|
|
8 Apr 2003, 00:38
|
#6
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Quote:
Originally posted by meglamaniac
Forgive me here - why does using "." work?
I'm really too tired to understand the answer so I'll look tomorrow morning.
|
. concatenates strings: "a"."b" => "ab"
|
|
|
8 Apr 2003, 01:54
|
#7
|
Ball
Join Date: Oct 2001
Posts: 4,410
|
Quote:
Originally posted by meglamaniac
I would learn perl if I could be bothered but I don't have much free time at the moment and I allready have most of the knowledge I need (ie. the C/C++ and some basic MySQL) to get going in PHP very quickly.
|
I don't see why MySQL is relevant, but PHP really isn't that similar to C/C++. In PHP you get lots of complications like the one you've mentioned, it's a more complex language. You end up having to learn a lot more than if you use something simpler.
For example, in C you have lexical scoping like in ALGOL, in PHP you have either globals or function scope. I've seen a lot of programmer time wasted trying to use stuff like this.
Just making conversation, really.
|
|
|
8 Apr 2003, 09:35
|
#8
|
Join Date: Jan 2002
Posts: 421
|
Quote:
Originally posted by meglamaniac
Forgive me here - why does using "." work?
I'm really too tired to understand the answer so I'll look tomorrow morning.
I would learn perl if I could be bothered but I don't have much free time at the moment and I allready have most of the knowledge I need (ie. the C/C++ and some basic MySQL) to get going in PHP very quickly.
|
i believe it has something to do with echo (a,b); being 2 parameters (java-like?)
|
|
|
8 Apr 2003, 10:19
|
#9
|
Born Sinful
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
|
Flav, it just had be confused that in the PHP doc for echo it stated arguments were seperated by commas. Obviously there are inconsistencies around.
Quey, I'll need SQL queries at some point - I can't hide from databasing for ever and it's something I want to mess with anyway.
Maybe PHP isn't as similar to C as I originally thought but I'm going to stick with it for now. I can allways learn perl when I've got more time.
__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
|
|
|
8 Apr 2003, 10:30
|
#10
|
Registered User
Join Date: Mar 2001
Posts: 205
|
Code:
printf("<br> %s", fgets($handle,300));
something like that'd work wouldnt it ?
__________________
#linux - home of idiots
#impulsed - home of genius..?
|
|
|
8 Apr 2003, 16:30
|
#11
|
Born Sinful
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
|
I never thought of using printf - dumb considering th eammount of use I give it in C.
I notice you still have to give a type for the variable to be dissplayed despite the way PHP autotypes variables; a legacy from C days, or there for added user control?
Ta anyway slidey.
__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
|
|
|
8 Apr 2003, 16:41
|
#12
|
Registered User
Join Date: Mar 2001
Posts: 205
|
__________________
#linux - home of idiots
#impulsed - home of genius..?
|
|
|
8 Apr 2003, 16:48
|
#13
|
Born Sinful
Join Date: Nov 2000
Location: Loughborough, UK
Posts: 4,059
|
Slidey - you have an (unrelated) PM.
__________________
Worth dying for. Worth killing for. Worth going to hell for. Amen.
|
|
|
8 Apr 2003, 16:58
|
#14
|
Registered User
Join Date: Mar 2001
Posts: 205
|
replied
__________________
#linux - home of idiots
#impulsed - home of genius..?
|
|
|
|
All times are GMT +1. The time now is 18:39.
| |