denoteone Posted March 23, 2010 Share Posted March 23, 2010 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"; } } Quote Link to comment https://forums.phpfreaks.com/topic/196226-echo-html-and-php-variable-not-working/ Share on other sites More sharing options...
trq Posted March 23, 2010 Share Posted March 23, 2010 Its pretty hard to tell what you are trying to do.... is test meant to be a variable? echo '<div>' . $test . '</div><br/><br/><br/>'; Quote Link to comment https://forums.phpfreaks.com/topic/196226-echo-html-and-php-variable-not-working/#findComment-1030490 Share on other sites More sharing options...
KevinM1 Posted March 23, 2010 Share Posted March 23, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/196226-echo-html-and-php-variable-not-working/#findComment-1030493 Share on other sites More sharing options...
denoteone Posted March 23, 2010 Author Share Posted March 23, 2010 Thanks again Nightslyr. I actually was having this issue yesterday and now that I am coming back to it this morning I am not sure how I didn't notice I was concatenate two echo statements. Quote Link to comment https://forums.phpfreaks.com/topic/196226-echo-html-and-php-variable-not-working/#findComment-1030495 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.