Wrox Programmer Forums
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 10th, 2004, 05:43 PM
Registered User
 
Join Date: Feb 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to dean_custom
Default Parse Error :-(

Parse error: parse error, unexpected T_ECHO

my code is as follows....

<? php echo '<h2>Hello</h2>' ?>

i have also tried....

<? php
echo 'hello';
?>

both times i get the same error "Parse error: parse error, unexpected T_ECHO"

I'm running IIS v5.1 and PHP ( maybe there's some IIS configuration i need to change??... HELP!!.. i'm PHP'd OFF
 
Old February 10th, 2004, 05:59 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

A parse error always means an error in code syntax, or a typo.

In your case the typo is in the opening <?php delimiter, you have a space between '<?' and 'php'... remove the space.

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
 
Old February 10th, 2004, 11:30 PM
Registered User
 
Join Date: Feb 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to dean_custom
Default

*MSG TO SELF* You're a moron. Why don't you pay attention to syntax you idiot!! lol.... I have another question now... how do you initialize variables in PHP? I'm doing ..

$IpAddress = env(REMOTE_ADDR);

it works and all.. but it says REMOTE_ADDR wasn't initalized or something... i tried java style and c style code..but i think i'm just too stupid.... lmao

 
Old February 11th, 2004, 02:12 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

lol, that's ok. I can remember being a beginner too.

PHP doesn't require variable initialization. A variable is intialized when it is created, and PHP automatically attempts to figure out what you intend the type to be based on the context with which it is used.

If you compare a variable and it is not initialized PHP will automatically, temporarily, create a copy of the varible in memory with NULL value for comparison purposes, if you aren't using certain language constructs (like isset and empty) PHP may complain in the form of a notice level error which happens with variables, arrays and constants when used before created.

PHP compares most closely with PERL, IMO, while the control structures are very similar to what you would find in C and Java.

Here is easily the most helpful URL you'll need when dealing with PHP:
http://www.php.net/manual/en/

Start at the top, you can probably skip section I, but section II contains basic information about how variables may be used, security, control structures, predefined variables, all the basics. Its pretty dry reading, it doesn't do much hand holding, but there is a wealth of information in there.

That being said, you can get the remote address from the $_SERVER superglobal, which contains a set of predefined variables set by the HTTP SERVER.. the indices in this array aren't gauranteed to be the same between different HTTP servers,

Reference it like this:

echo $_SERVER["REMOTE_ADDR"];

Your script:
$IpAddress = env(REMOTE_ADDR);

The program will look for a user-defined function named 'env' and attempt to pass the constant REMOTE_ADDR to it. Constants in PHP are just like variables, but they can be set only once, do not have a dollar sign, and must be set using the built in define() function. If a constant is used before being set it is assumed the string literal, PHP will complain in the form of a notice level error and continue on with execution. In your case you probably got a fatal error from 'env' not being a defined function.

You can use this script to find variables set in the array:

<?php
phpinfo();
?>

This prints out a detailed output of configuration and enviornment settings.

Additionally, the PHP manual notes those indices which can be expected to appear in the array:
http://www.php.net/manual/en/reserve...riables.server

Here is the specific URL for predefined variables:
http://www.php.net/manual/en/languag...predefined.php



:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse error: syntax error, unexpected T_ELSE in /h vipin k varghese BOOK: XSLT Programmer's Reference, 2nd Edition 4 September 29th, 2011 01:19 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
PHP Parse error: parse error, unexpected T_STRING geminient PHP How-To 4 August 18th, 2007 02:27 AM
Parse error: parse error, unexpected $end Ayodeji Adegbaju Pro PHP 3 January 12th, 2007 12:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.