Jump to content

A simple php echo question


egorig

Recommended Posts

Which one is the best :

echo ("My name is $name");

echo "My name is $name";

echo "My name is ".$name."";    i use this ! but is it better than the previous one? Is it necessary to concatenate?

echo ("My name is ".$name."");

echo "My name is "; echo $name;

 

Link to comment
Share on other sites

Either one works, but the best all depends on your style.

 

Personally my favorite would be this:

 

<?php
echo "My name is " . $name;
?>

 

strictly because that way I know no funny business will happen to my variables. That is just how I do it.

Link to comment
Share on other sites

honestly... its really down to personal preference...

personally... i template everything... so all my stuff is stored in strings, untill it hits the template.php in which is 99% html code... where i <?=$var?>

Link to comment
Share on other sites

honestly... its really down to personal preference...

personally... i template everything... so all my stuff is stored in strings, untill it hits the template.php in which is 99% html code... where i <?=$var?>

 

What does it do?

<?php
<?=$var?>
?>

Link to comment
Share on other sites

honestly... its really down to personal preference...

personally... i template everything... so all my stuff is stored in strings, untill it hits the template.php in which is 99% html code... where i <?=$var?>

 

What does it do?

<?php
<?=$var?>
?>

 

Nothing anymore it has been depreciated. Best practice is to use this:

 

<html>
<title><?php print $var; ?></title>

 

Essentially what it used to do was just print a variable to the string, but some issues arose with that so they made that functionality depreciated as of 4.4 I believe not sure.

 

Anyhow if you plan on upgrading php anytime soon that will break anyscripts that use that methodology.

Link to comment
Share on other sites

honestly... its really down to personal preference...

personally... i template everything... so all my stuff is stored in strings, untill it hits the template.php in which is 99% html code... where i <?=$var?>

 

What does it do?

<?php
<?=$var?>
?>

 

Nothing anymore it has been depreciated. Best practice is to use this:

 

<html>
<title><?php print $var; ?></title>

 

Essentially what it used to do was just print a variable to the string, but some issues arose with that so they made that functionality depreciated as of 4.4 I believe not sure.

 

Anyhow if you plan on upgrading php anytime soon that will break anyscripts that use that methodology.

 

What type of issues arosed?

Link to comment
Share on other sites

i've ran php 4.x, 5, 5.2, and have yet to find one where <?=$var?> doesnt work... besides... most of other php upgrades have been backwards compatable... i dont see why they'd cut this... maybe its not cool enough... lol

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.