Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #6566 > unrolled thread

Stuck on Exercise 1

Started bytim.whittingham@googlemail.com
First post2012-07-15 05:03 -0700
Last post2012-07-15 16:06 +0200
Articles 13 — 9 participants

Back to article view | Back to comp.lang.php


Contents

  Stuck on Exercise 1 tim.whittingham@googlemail.com - 2012-07-15 05:03 -0700
    Re: Stuck on Exercise 1 The Natural Philosopher <tnp@invalid.invalid> - 2012-07-15 13:16 +0100
      Re: Stuck on Exercise 1 Christoph Becker <cmbecker69@gmx.de> - 2012-07-15 14:42 +0200
        Re: Stuck on Exercise 1 The Natural Philosopher <tnp@invalid.invalid> - 2012-07-15 13:49 +0100
          Re: Stuck on Exercise 1 Tim Streater <timstreater@greenbee.net> - 2012-07-15 15:24 +0100
            Re: Stuck on Exercise 1 The Natural Philosopher <tnp@invalid.invalid> - 2012-07-15 21:38 +0100
      Re: Stuck on Exercise 1 Jerry Stuckle <jstucklex@attglobal.net> - 2012-07-15 09:37 -0400
      Re: Stuck on Exercise 1 Tim Streater <timstreater@greenbee.net> - 2012-07-15 15:19 +0100
      Re: Stuck on Exercise 1 Arno Welzel <usenet@arnowelzel.de> - 2012-07-16 14:24 +0200
    Re: Stuck on Exercise 1 Shake <alex.estevezQUENO@QUENOfilnet.es> - 2012-07-15 15:28 +0200
      Re: Stuck on Exercise 1 tim.whittingham@googlemail.com - 2012-07-15 07:07 -0700
      Re: Stuck on Exercise 1 Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-07-15 16:18 +0200
    Re: Stuck on Exercise 1 "J.O. Aho" <user@example.net> - 2012-07-15 16:06 +0200

#6566 — Stuck on Exercise 1

Fromtim.whittingham@googlemail.com
Date2012-07-15 05:03 -0700
SubjectStuck on Exercise 1
Message-ID<a9778401-6b17-4963-aeeb-30e64816aa6e@googlegroups.com>
To my great embarassment. Came away with a copy of PHP5 & 
MySQL Bible thinking to do a couple of hours study 
every day of my hols with a view to learning a little 
elementary PHP to assist me with my CMS website work. 
Read through the first couple of Chapters until I came to 
Chapter 4 and 'Your First PHP Program 'Hello World'' in 
which I am instructed to type 

<HTML>
<HEAD>
<TITLE>My first PHP program</TITLE>
</HEAD>
<BODY>
<?php
print(“Hello, cruel world<BR><BR>\n”);
phpinfo();
?>
</BODY>
</HTML>

Saved as .html and viewed with Wampserver I got nothing 

but

\n”); phpinfo(); ?> 

on the resulting page. Copied and pasted in case of 
typos, same result. Installed EasyPHP and got the same 
result. Uploaded file to webserver and viewed it on the 
web: 

\n”); phpinfo(); ?> 

on its own and nothing but.

Humph. So, Help please.

Tim W

[toc] | [next] | [standalone]


#6567

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2012-07-15 13:16 +0100
Message-ID<jtucba$78l$6@news.albasani.net>
In reply to#6566
tim.whittingham@googlemail.com wrote:
> To my great embarassment. Came away with a copy of PHP5 & 
> MySQL Bible thinking to do a couple of hours study 
> every day of my hols with a view to learning a little 
> elementary PHP to assist me with my CMS website work. 
> Read through the first couple of Chapters until I came to 
> Chapter 4 and 'Your First PHP Program 'Hello World'' in 
> which I am instructed to type 
> 
> <HTML>
> <HEAD>
> <TITLE>My first PHP program</TITLE>
> </HEAD>
> <BODY>
> <?php
> print(“Hello, cruel world<BR><BR>\n”);
> phpinfo();
> ?>
> </BODY>
> </HTML>
> 
> Saved as .html and viewed with Wampserver I got nothing 
> 
> but
> 
> \n”); phpinfo(); ?> 
> 
> on the resulting page. Copied and pasted in case of 
> typos, same result. Installed EasyPHP and got the same 
> result. Uploaded file to webserver and viewed it on the 
> web: 
> 
> \n”); phpinfo(); ?> 
> 
> on its own and nothing but.
> 
> Humph. So, Help please.
> 
> Tim W

AFAIK all php programs MUST start with <?php even if they are 
immediately reverted to text with ?>

So try

<?php ?>

as the first line.

> 
> 


-- 
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.

[toc] | [prev] | [next] | [standalone]


#6568

FromChristoph Becker <cmbecker69@gmx.de>
Date2012-07-15 14:42 +0200
Message-ID<jtudrq$bav$1@speranza.aioe.org>
In reply to#6567
The Natural Philosopher wrote:
> AFAIK all php programs MUST start with <?php even if they are
> immediately reverted to text with ?>

No. It's even legal for a PHP file to contain HTML only (without any
<?php ...?>).

But to be processed as PHP the webserver has to know, that it's a PHP
file. This is typically done by saving the file as *.php instead of *.html

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#6569

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2012-07-15 13:49 +0100
Message-ID<jtue8q$clc$1@news.albasani.net>
In reply to#6568
Christoph Becker wrote:
> The Natural Philosopher wrote:
>> AFAIK all php programs MUST start with <?php even if they are
>> immediately reverted to text with ?>
> 
> No. It's even legal for a PHP file to contain HTML only (without any
> <?php ...?>).
> 
> But to be processed as PHP the webserver has to know, that it's a PHP
> file. This is typically done by saving the file as *.php instead of *.html
> 
Really?  I must try that..

I have to say I never bothered to write a php file that didn't start 
with  <?php



-- 
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.

[toc] | [prev] | [next] | [standalone]


#6576

FromTim Streater <timstreater@greenbee.net>
Date2012-07-15 15:24 +0100
Message-ID<timstreater-E790F6.15243415072012@news.individual.net>
In reply to#6569
In article <jtue8q$clc$1@news.albasani.net>,
 The Natural Philosopher <tnp@invalid.invalid> wrote:

> Christoph Becker wrote:
> > The Natural Philosopher wrote:
> >> AFAIK all php programs MUST start with <?php even if they are
> >> immediately reverted to text with ?>
> > 
> > No. It's even legal for a PHP file to contain HTML only (without any
> > <?php ...?>).
> > 
> > But to be processed as PHP the webserver has to know, that it's a PHP
> > file. This is typically done by saving the file as *.php instead of *.html
> > 
> Really?  I must try that..
> 
> I have to say I never bothered to write a php file that didn't start 
> with  <?php

You don't even *have* to use a .php suffix, either. You could use .shit 
if you wanted to. But you'd have to configure apache or whatever to 
recognise that scripts whose names end in .shit have PHP in them, to be 
interpreted please.

The only reason that .php typically works is because the default config 
for apache contains the necessary configuration commands for having the 
.php work as you'd expect. If you remove that, however, it won't 
recognise *any* file as having PHP in it, to be interpreted please.

I use .phtml, personally.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#6581

FromThe Natural Philosopher <tnp@invalid.invalid>
Date2012-07-15 21:38 +0100
Message-ID<jtv9o4$7r1$6@news.albasani.net>
In reply to#6576
Tim Streater wrote:
> In article <jtue8q$clc$1@news.albasani.net>,
> The Natural Philosopher <tnp@invalid.invalid> wrote:
> 
>> Christoph Becker wrote:
>> > The Natural Philosopher wrote:
>> >> AFAIK all php programs MUST start with <?php even if they are
>> >> immediately reverted to text with ?>
>> > > No. It's even legal for a PHP file to contain HTML only (without any
>> > <?php ...?>).
>> > > But to be processed as PHP the webserver has to know, that it's a PHP
>> > file. This is typically done by saving the file as *.php instead of 
>> *.html
>> > Really?  I must try that..
>>
>> I have to say I never bothered to write a php file that didn't start 
>> with  <?php
> 
> You don't even *have* to use a .php suffix, either. You could use .shit 
> if you wanted to. 

An attractive propsition...


> But you'd have to configure apache or whatever to 
> recognise that scripts whose names end in .shit have PHP in them, to be 
> interpreted please.
> 
You would have thought that was the default... :-)

> The only reason that .php typically works is because the default config 
> for apache contains the necessary configuration commands for having the 
> .php work as you'd expect. If you remove that, however, it won't 
> recognise *any* file as having PHP in it, to be interpreted please.
> 
> I use .phtml, personally.
> 


-- 
To people who know nothing, anything is possible.
To people who know too much, it is a sad fact
that they know how little is really possible -
and how hard it is to achieve it.

[toc] | [prev] | [next] | [standalone]


#6571

FromJerry Stuckle <jstucklex@attglobal.net>
Date2012-07-15 09:37 -0400
Message-ID<jtuh3i$la0$1@dont-email.me>
In reply to#6567
On 7/15/2012 8:16 AM, The Natural Philosopher wrote:
> tim.whittingham@googlemail.com wrote:
>> To my great embarassment. Came away with a copy of PHP5 & MySQL Bible
>> thinking to do a couple of hours study every day of my hols with a
>> view to learning a little elementary PHP to assist me with my CMS
>> website work. Read through the first couple of Chapters until I came
>> to Chapter 4 and 'Your First PHP Program 'Hello World'' in which I am
>> instructed to type
>> <HTML>
>> <HEAD>
>> <TITLE>My first PHP program</TITLE>
>> </HEAD>
>> <BODY>
>> <?php
>> print(“Hello, cruel world<BR><BR>\n”);
>> phpinfo();
>> ?>
>> </BODY>
>> </HTML>
>>
>> Saved as .html and viewed with Wampserver I got nothing
>> but
>>
>> \n”); phpinfo(); ?>
>> on the resulting page. Copied and pasted in case of typos, same
>> result. Installed EasyPHP and got the same result. Uploaded file to
>> webserver and viewed it on the web:
>> \n”); phpinfo(); ?>
>> on its own and nothing but.
>>
>> Humph. So, Help please.
>>
>> Tim W
>
> AFAIK all php programs MUST start with <?php even if they are
> immediately reverted to text with ?>
>
> So try
>
> <?php ?>
>
> as the first line.
>

We know you don't know much, don't we?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#6575

FromTim Streater <timstreater@greenbee.net>
Date2012-07-15 15:19 +0100
Message-ID<timstreater-CD45FA.15193115072012@news.individual.net>
In reply to#6567
In article <jtucba$78l$6@news.albasani.net>,
 The Natural Philosopher <tnp@invalid.invalid> wrote:

> AFAIK all php programs MUST start with <?php even if they are 
> immediately reverted to text with ?>
> 
> So try
> 
> <?php ?>
> 
> as the first line.

Mmmm, no. If f'rinstance you're running it as a CLI script you'd prolly 
want it to start:

#!/usr/bin/php
<?php

etc.

If OTOH you have it as a script for apache to run, it doesn't matter. 
You can start with plain text, which will just be sent to the browser. 
Any <?php ?> blocks are interpreted and any output they produce will be 
sent to the browser. You can as many such blocks as you like with text 
in between, or none at all. Or put everything inside one such block.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#6588

FromArno Welzel <usenet@arnowelzel.de>
Date2012-07-16 14:24 +0200
Message-ID<ju116r$k58$2@dont-email.me>
In reply to#6567
Am 15.07.2012 14:16, schrieb The Natural Philosopher:

> tim.whittingham@googlemail.com wrote:
>> To my great embarassment. Came away with a copy of PHP5 & MySQL Bible
>> thinking to do a couple of hours study every day of my hols with a
>> view to learning a little elementary PHP to assist me with my CMS
>> website work. Read through the first couple of Chapters until I came
>> to Chapter 4 and 'Your First PHP Program 'Hello World'' in which I am
>> instructed to type
>> <HTML>
>> <HEAD>
>> <TITLE>My first PHP program</TITLE>
>> </HEAD>
>> <BODY>
>> <?php
>> print(“Hello, cruel world<BR><BR>\n”);
>> phpinfo();
>> ?>
>> </BODY>
>> </HTML>
>>
>> Saved as .html and viewed with Wampserver I got nothing
>> but

Why do you expect, that ".html" is interpreted as PHP script? Of course 
it should be saved as ".php".

>> \n”); phpinfo(); ?>
>> on the resulting page. Copied and pasted in case of typos, same
>> result. Installed EasyPHP and got the same result. Uploaded file to
>> webserver and viewed it on the web:
>> \n”); phpinfo(); ?>
>> on its own and nothing but.
>>
>> Humph. So, Help please.
>>
>> Tim W
>
> AFAIK all php programs MUST start with <?php even if they are
> immediately reverted to text with ?>

No.

>
> So try
>
> <?php ?>
>
> as the first line.

No - this is not neccessary and no it does not make the webserver 
believe it should forward HTML files to PHP. See above - the extension 
is the key - ".php" and not ".html".


-- 
Arno Welzel
http://arnowelzel.de
http://de-rec-fahrrad.de

[toc] | [prev] | [next] | [standalone]


#6570

FromShake <alex.estevezQUENO@QUENOfilnet.es>
Date2012-07-15 15:28 +0200
Message-ID<jtugh6$ipg$1@dont-email.me>
In reply to#6566
> print(“Hello, cruel world<BR><BR>\n”);


This double qoutes you are using... Looks like the type of quotes that 
some word processors like "Microsoft word" uses... And are not valid
characters.

“ And ” are not the same that "

Perhaps the PHP is doing and error and you have the error display 
disabled.

if the file extension is .html can be that the file is not processed 
bye the PHP and delivered as is to the browser. Then, you can look the 
source code through the browser And see the php on it.


Try using .php as the file extension. Try also using the correct double 
quote character.

Regards

[toc] | [prev] | [next] | [standalone]


#6573

Fromtim.whittingham@googlemail.com
Date2012-07-15 07:07 -0700
Message-ID<3807be27-0fdb-4ed6-a349-7952a555c84b@googlegroups.com>
In reply to#6570
On Sunday, July 15, 2012 2:28:05 PM UTC+1, Shake wrote:
> &gt; print(“Hello, cruel world&lt;BR&gt;&lt;BR&gt;\n”);
> 
> 
> This double qoutes you are using... Looks like the type of quotes that 
> some word processors like &quot;Microsoft word&quot; uses... And are not valid
> characters.
> 
> “ And ” are not the same that &quot;
> 
> Perhaps the PHP is doing and error and you have the error display 
> disabled.
> 
> if the file extension is .html can be that the file is not processed 
> bye the PHP and delivered as is to the browser. Then, you can look the 
> source code through the browser And see the php on it.
> 
> 
> Try using .php as the file extension. Try also using the correct double 
> quote character.
> 
> Regards


It works, you were correct on both errors. My book is in pdf so I had copied and pasted directly from the text into notepad++ thinking it was sure to be correct,lol. And the extension I had as .html, so thank you, I can continue my learning now. 

Tim W

[toc] | [prev] | [next] | [standalone]


#6574

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-07-15 16:18 +0200
Message-ID<1600792.oMNUckLgyt@PointedEars.de>
In reply to#6570
Shake wrote:

>> print(“Hello, cruel world<BR><BR>\n”);
> 
> This double qoutes you are using... Looks like the type of quotes that
> some word processors like "Microsoft word" uses... And are not valid
> characters.

Those typographical double quotes characters are valid (they are defined in 
Unicode, after all), but the (PHP) source code is not, because they are not 
string literal delimiters (in PHP).


PointedEars
-- 
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann

[toc] | [prev] | [next] | [standalone]


#6572

From"J.O. Aho" <user@example.net>
Date2012-07-15 16:06 +0200
Message-ID<a6g137F7duU1@mid.individual.net>
In reply to#6566
On 15/07/12 14:03, tim.whittingham@googlemail.com wrote:

> elementary PHP to assist me with my CMS website work.
> Read through the first couple of Chapters until I came to
> Chapter 4 and 'Your First PHP Program 'Hello World'' in
> which I am instructed to type
>
> <HTML>
> <HEAD>
> <TITLE>My first PHP program</TITLE>
> </HEAD>
> <BODY>
> <?php
> print(“Hello, cruel world<BR><BR>\n”);
> phpinfo();
> ?>
> </BODY>
> </HTML>

As Shake already pointed out, the “ and ” ain't the same as " and you 
should use a text editor instead of an office application to edit your 
php scripts.
As you seems to be a microsoft user, I suggest you download and install 
notepad++ and you find their homepage at http://notepad-plus-plus.org


> Saved as .html and viewed with Wampserver I got nothing

This will tell your Apache that the file will be an html file and it 
will not be parsed by the php engine (contrary to what The Natural 
Philosopher wrote). You need to either reconfigure your Apache to handle 
all .html files as php scripts (this will mean all files ending with 
.html will be parsed by the php engine and give overhead for your 
computer if you are serving plain html files), the best solution is to 
name the file to end with .php and the file will be parsed by the php 
engine.

> but
>
> \n”); phpinfo(); ?>

This for your script file isn't a plain html file, so it will try it's 
best to understand your HTML and present what you wrote, if you would 
choose to look at the source of the HTML page in your browser, you will 
see it's exactly the same as what you wrote in your file.


-- 

  //Aho

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web