Jump to content

echo html and php variable not working


denoteone

Recommended Posts

when I insert

echo '<div>'. echo "test"; .'</div><br/><br/><br/>';

This code breaks my page and I am not getting an error message.  below is the whole block of code

 

for ($i = 0; $i < 21; $i++)
					{

			if (($i + 1) % 3 == 0 )
  							 { 
      echo '<div>'. echo "test"; .'</div><br/><br/><br/>';
   							 }else{

       echo "test2";
   								}
					}	

Link to comment
https://forums.phpfreaks.com/topic/196226-echo-html-and-php-variable-not-working/
Share on other sites

You can't concatenate echo statements.  In other words:

 

echo 'something' . echo 'something else';

 

Doesn't work.  You should concatenate the strings instead:

 

echo '<div>' . 'test' . '</div><br/><br/><br/>';

 

Of course, this can (and should) be treated as just one string, as you're not gaining anything by concatenating here.

 

echo '<div>test</div><br /><br /><br />';

 

Also, when using double-quoted strings, you don't need to concatenate to display a variable's contents.  So:

 

echo "<div>$test</div><br /><br /><br />";

 

Will print out the value of $test within that div.

 

echo '<div>$test</div><br /><br /><br />';

 

Will simply print out $test itself.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.