How to Use Echo Inside Echo

PHP echo inside echo

That is some of the ugliest code I have ever seen...

<?php 
echo '
<h3>Hello</h3>';

while ($row_indiosct = mysql_fetch_assoc($indiosct))
{
echo '
<div class="indios">
<a href="indio.php?id='.$row_indiosct['id'].'">
<img src="galeria/indios/'. $row_indiosct['foto'].'" alt="'.$row_indiosct['nome'].'" />
<br />'.$row_indiosct['nome'].'</a>
</div>';
}
?>

You could also use the HEREDOC syntax.

How to use echo inside echo

echo '<form method="post" class="product" action="index.php" id="addtocartproduct '. $products->virtuemart_product_id.' ">';

PHP - echo inside an echo

why did you open a <?php tag again, you are already in echo line?

echo '<td align="left"><a href="'.url('Forum/create_new_post?topic_id='.$post->topic_id.'&forum_id='.$post->forum_id.'').'"><img src="'.SITE_URL.'/lib/skins/flyeuro/images/forums/t_reply.gif"/></a></td>';

and what is SITE_URL? Is that a variable, did you forget to put $?


echo prints out the string that you gave as parameter,

echo "foo";

As @hakre mentioned about it, . is used to concatenate strings.

$var = "foo"."bar";  //foobar

So you can use it in echo line,

$var = "foo"."bar";  //foobar
echo "foo "."bar ".$var // foo bar foobar

And It's not important weather variable defined as a string. It would be a constant variable.

define('SITE_URL', 'localhost:8080/phpvms'); 
echo "my website URL is ".SITE_URL; //my website URL is localhost:8080/phpvms

Echo inside echo PHP

You can't have PHP tags between PHP tags. Concat the strings instead:

if (is_single()) { 

echo '<div><p>html</p>' . do_shortcode( '[contact-form-7 id="1" title="contact form"]' ) . '</div>';

} ?>

echo a command that echoes a quoted string

You can escape the quote characters with \:

echo "echo\"Hello\"">>script2

Alternatively, use single quotes to ignore special characters inside the string:

echo 'echo"Hello"'>>script2


Related Topics



Leave a reply



Submit