Is it possible to echo in single quotes with a variable?
Example
echo 'I love my $variable.';
I need to do this because I have a lot of HTML for echo.
You should either use:
echo 'I love my ' . $variable . '.';
This method adds a variable to the string.
Or you could use:
echo "I love my $variable.";
Check out the double quotes used here!
If there is a lot of text, look at the Heredoc syntax.
$var = <<<EOT <div style="">Some 'text' {$variable}</div> EOT;
:
: heredoc, variables escape- .
, , .
echo HTML.
echo
, , † HTML. PHP HTML:
<div class="foo"> <span><?php echo $value; ?></span> </div>
†: heredoc [docs] .
heredoc
. ( ) , . , :
echo 'I love my '.$variable.'.';
HTML, , doble:
echo "<a href=\"$url\">$text</a>";
. PHP , , .
. ' .
'
echo "I love my {$variable}. And I have \" some characters escaped";
, .
echo "I love my \"$variable\".";
php echo ( ).
I love my <?php echo $variable; ?>. With short tags enabled, I love my <?=$variable?>.
, heredoc, , .
echo <<<HTML I love my $variable. '"... HTML;
php.net: ". heredoc, escape- , ."
, - , . :
echo 'I love my' . $variable . '.';
.
Besides the solutions mentioned by other users, such as string concatenation, you can use placeholders as follows:
Note that% s is for the string.
$variable = 'what ever'; printf('The $variable is %s', $variable);
Try it
<php echo 'I love my '. $variable . ' .'; ?>
use the escape escape quote to surround the text string as follows:
variable='my dog' echo \''I love ' $variable\'
=> "I love my dog"
Or a simple way:
awk "\$1 < $variable"