Page 1 of 1
php syntax??
Posted: Thu Dec 11, 2003 10:11 am
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]?>"
Posted: Thu Dec 11, 2003 10:58 am
by microthick
I often use this method:
<input type="hidden" name="city" value="<?= $_POST["city"] ?>">
Works like a charm.
Posted: Thu Dec 11, 2003 11:03 am
by JayBird
apparently it isn't advisory to use this method
Mark
Posted: Thu Dec 11, 2003 11:18 am
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.
Posted: Thu Dec 11, 2003 11:20 am
by JayBird
i actually think it is an option in the php.ini.
<?php ?> <------ this always works, so you should use that really
Mark
Posted: Thu Dec 11, 2003 11:20 am
by microthick
Bech100 wrote:apparently it isn't advisory to use this method
Mark
Says who?
Posted: Thu Dec 11, 2003 11:21 am
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
Posted: Thu Dec 11, 2003 11:29 am
by microthick
Re: php syntax??
Posted: Thu Dec 11, 2003 11:30 am
by vigge89
Code: Select all
<input type="hidden" name="city" value="<?=(stripslashes($_POSTїcity]))?>" >
Will that really work?
i think it should be
Code: Select all
<input type="hidden" name="city" value="<?php echo stripslashes($_POSTїcity]) ?>" >
Posted: Thu Dec 11, 2003 12:30 pm
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.
Posted: Thu Dec 11, 2003 11:23 pm
by volka
http://www.php.net/manual/en/configuration.directives.phpshort_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 <?=
Posted: Thu Dec 11, 2003 11:25 pm
by Nay
Now people, are you forgetting something?
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

.
-Nay