Jump to content

Recommended Posts

How can I post this variable $healspell when I already have an echo within a php?

 

Here's what I have:

 


				echo '<p>You cast Nature\'s Cure (Recovered <?=$healspell?>)</p>';

 

It's not printing anything out at the moment, obviously, and if I just put $healspell, it just echos out: $healspell.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/261864-posting-php-in-an-echo/
Share on other sites

You can either use interpolation (which requires double quotes):

echo "
You cast Nature's Cure (Recovered {$healspell})";

 

Or concatenation (you can use single or double):

echo '
You cast Nature\'s Cure (Recovered ' . $healspell . ')';

 

There are a few other ways, but these are most common.

You can either use interpolation (which requires double quotes):

echo "<p>You cast Nature's Cure (Recovered {$healspell})</p>";

There are a few other ways, but these are most common.

 

You shouldn't need the {} for this. You'd use it for an array value but a regular variable, no need.

You can either use interpolation (which requires double quotes):

echo "
You cast Nature's Cure (Recovered {$healspell})";

There are a few other ways, but these are most common.

 

You shouldn't need the {} for this. You'd use it for an array value but a regular variable, no need.

I prefer them for readability.  But if you want to get picky, you only need them for String keys.

I prefer them for readability.  But if you want to get picky, you only need them for String keys.

 

or object methods. [/picky] ;)

 

<?php

class foo {
public function bar() { return 'baz'; }
}

$obj = new foo;
echo "How would you like a nice of {$obj->bar()}";

?>

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.