php syntax??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

php syntax??

Post by oldtimer »

I saw some code and dont know if it works. Here is what they had.

Code: Select all

<input type="hidden" name="city" value="<?=(stripslashes($_POSTїcity]))?>" >
Also saw a

Code: Select all

<input type="hidden" name="city" value="<?=$_POSTїcity]?>" >
where as I normally do either a

Code: Select all

<input type="hidden" name="city" value="<? echo $_POSTїcity]; ?>" >

Code: Select all

<?php
echo "<input type="hidden" name="city" value="$_POST[city]" >";
?>
So does the code they use work. Ie putting in the ="<?=$_POST[city]?>"
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

I often use this method:

<input type="hidden" name="city" value="<?= $_POST["city"] ?>">

Works like a charm.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

apparently it isn't advisory to use this method

Code: Select all

<?= $_POST["city"] ?>
Mark
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

well you must have to have a certain php version to use the <?= $_POST["city"] ?>


It did not work on the one I was trying so that is why I asked here.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

i actually think it is an option in the php.ini.

<?php ?> <------ this always works, so you should use that really

Mark
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Bech100 wrote:apparently it isn't advisory to use this method

Code: Select all

<?= $_POST["city"] ?>
Mark
Says who?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

me :p

no, i read it somewhere on this forum but can't find it now. it wasn't that long ago

Mark
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

I recall this thread:
viewtopic.php?t=15303&highlight=
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Re: php syntax??

Post by vigge89 »

Code: Select all

<input type="hidden" name="city" value="<?=(stripslashes($_POST&#1111;city]))?>" >
Will that really work?

i think it should be

Code: Select all

<input type="hidden" name="city" value="<?php echo stripslashes($_POST&#1111;city]) ?>" >
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

I think you should have the echo there or echo out the entire <input> line. But just did not know if that =$_POST worked or not.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://www.php.net/manual/en/configuration.directives.php
short_open_tag boolean

Tells whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use <?xml ?> inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"'; ?>. Also if disabled, you must use the long form of the PHP open tag (<?php ?>).

Note: This directive also affects the shorthand <?=, which is identical to <? echo. Use of this shortcut requires short_open_tag to be on.
It's not a special version of php it's a matter of configuration.
If you do not have control of the php installation/configuration you should avoid using <?=
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Now people, are you forgetting something? 8)

oldtimer, there's also another way, ahem:

Code: Select all

function stripAll($array) {

   foreach ${$array} as $key => $value {
      ${$array}["$key"] = stripslashes($value);
   }

}

stripAll($_POST);
echo <<< INPUT
<input type="hidden" name="city" value="{$_POST['city']}" />
INPUT;
Now how lazy can I get 8).

-Nay
Post Reply