Jump to content

Archived

This topic is now archived and is closed to further replies.

schawel

PHP shorthand BAD coding

Recommended Posts

<input type="text" name="email" size="35" value="" class="input">&nbsp;
<input type="hidden" name="mail_message" value="<?=$message?>">
<input type="submit" name="sendemail" class="input" value=" Send " onClick="return validate();">



I have this code and it looks like shorthand is being used for this. I was handed this code to try and clean it up.

<?=$message?> I don't recog this.

should it be <?php something = $message;?>

I have a whole page full of stuff like this

i.e. ----

<?=$val['fieldname']?>

or

<?=$_GET['id']?>


any ideas?

Share this post


Link to post
Share on other sites
The "<?=" is shorthand for "<?php echo "

Just replace "<?=" with "<? echo " and you should be set.

Ken

Share this post


Link to post
Share on other sites
[!--quoteo(post=355995:date=Mar 17 2006, 12:31 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 17 2006, 12:31 PM) [snapback]355995[/snapback][/div][div class=\'quotemain\'][!--quotec--]
The "<?=" is shorthand for "<?php echo "

Just replace "<?=" with "<? echo " and you should be set.

Ken
[/quote]


THANKS!!! u da man!

[!--quoteo(post=355999:date=Mar 17 2006, 12:40 PM:name=schawel)--][div class=\'quotetop\']QUOTE(schawel @ Mar 17 2006, 12:40 PM) [snapback]355999[/snapback][/div][div class=\'quotemain\'][!--quotec--]
THANKS!!! u da man!
[/quote]


ONE more thing

in my question..i sampled this

<?=$message?>

shouldn't there also be a semicolon after the variable $message

???

Share this post


Link to post
Share on other sites
No, it is optional if there is only one statement between the tags. Just like if there is only one statement in a statement block the curly braces are optional.

Ken

Share this post


Link to post
Share on other sites
To be precise, it doesn't matter if there is one or many statements. The last semicolon is implied by the "?>".

So this works OK

[code]<?php
echo '1';
echo '2';
echo '3'
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.