FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Stuck on Exercise 1
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Stuck on Exercise 1 [message #178639] Sun, 15 July 2012 12:03 Go to next message
tim.whittingham is currently offline  tim.whittingham
Messages: 2
Registered: July 2012
Karma: 0
Junior Member
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
Re: Stuck on Exercise 1 [message #178640 is a reply to message #178639] Sun, 15 July 2012 12:16 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
tim(dot)whittingham(at)googlemail(dot)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.
Re: Stuck on Exercise 1 [message #178641 is a reply to message #178640] Sun, 15 July 2012 12:42 Go to previous messageGo to next message
Christoph Becker is currently offline  Christoph Becker
Messages: 91
Registered: June 2012
Karma: 0
Member
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
Re: Stuck on Exercise 1 [message #178642 is a reply to message #178641] Sun, 15 July 2012 12:49 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
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.
Re: Stuck on Exercise 1 [message #178643 is a reply to message #178639] Sun, 15 July 2012 13:28 Go to previous messageGo to next message
Shake is currently offline  Shake
Messages: 40
Registered: May 2012
Karma: 0
Member
> 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
Re: Stuck on Exercise 1 [message #178644 is a reply to message #178640] Sun, 15 July 2012 13:37 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 7/15/2012 8:16 AM, The Natural Philosopher wrote:
> tim(dot)whittingham(at)googlemail(dot)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(at)attglobal(dot)net
==================
Re: Stuck on Exercise 1 [message #178645 is a reply to message #178639] Sun, 15 July 2012 14:06 Go to previous messageGo to next message
J.O. Aho is currently offline  J.O. Aho
Messages: 194
Registered: September 2010
Karma: 0
Senior Member
On 15/07/12 14:03, tim(dot)whittingham(at)googlemail(dot)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
Re: Stuck on Exercise 1 [message #178646 is a reply to message #178643] Sun, 15 July 2012 14:07 Go to previous messageGo to next message
tim.whittingham is currently offline  tim.whittingham
Messages: 2
Registered: July 2012
Karma: 0
Junior Member
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
Re: Stuck on Exercise 1 [message #178647 is a reply to message #178643] Sun, 15 July 2012 14:18 Go to previous messageGo to next message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
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
Re: Stuck on Exercise 1 [message #178648 is a reply to message #178640] Sun, 15 July 2012 14:19 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <jtucba$78l$6(at)news(dot)albasani(dot)net>,
The Natural Philosopher <tnp(at)invalid(dot)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
Re: Stuck on Exercise 1 [message #178649 is a reply to message #178642] Sun, 15 July 2012 14:24 Go to previous messageGo to next message
Tim Streater is currently offline  Tim Streater
Messages: 328
Registered: September 2010
Karma: 0
Senior Member
In article <jtue8q$clc$1(at)news(dot)albasani(dot)net>,
The Natural Philosopher <tnp(at)invalid(dot)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
Re: Stuck on Exercise 1 [message #178654 is a reply to message #178649] Sun, 15 July 2012 20:38 Go to previous messageGo to next message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma: 0
Senior Member
Tim Streater wrote:
> In article <jtue8q$clc$1(at)news(dot)albasani(dot)net>,
> The Natural Philosopher <tnp(at)invalid(dot)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.
Re: Stuck on Exercise 1 [message #178661 is a reply to message #178640] Mon, 16 July 2012 12:24 Go to previous message
Arno Welzel is currently offline  Arno Welzel
Messages: 317
Registered: October 2011
Karma: 0
Senior Member
Am 15.07.2012 14:16, schrieb The Natural Philosopher:

> tim(dot)whittingham(at)googlemail(dot)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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Lost $_SESSION in Google Chrome
Next Topic: Business Developer for IT company
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Mon Nov 25 20:15:47 GMT 2024

Total time taken to generate the page: 0.03632 seconds