Jump to content

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.

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.