Jump to content


Photo

PHP shorthand BAD coding


  • Please log in to reply
4 replies to this topic

#1 schawel

schawel
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 March 2006 - 08:27 PM

<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?

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 March 2006 - 08:31 PM

The "<?=" is shorthand for "<?php echo "

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

Ken

#3 schawel

schawel
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 March 2006 - 08:44 PM

[!--quoteo(post=355995:date=Mar 17 2006, 12:31 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 17 2006, 12:31 PM) View Post[/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) View Post[/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

???

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 March 2006 - 08:50 PM

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

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 17 March 2006 - 09:02 PM

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

<?php
echo '1';
echo '2';
echo '3'
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users