News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Code not going where I put it (HTML/PHP)

Started by Jade Elizabeth, January 03, 2015, 01:44:24 AM

Previous topic - Next topic

Jade Elizabeth

Getting extremely frustrated. All of my divs are ignoring their content and dumping it elsewhere. For example, this.....

TEMPLATE:
echo '
<div class="works">
<pre>' . print_r($context['works']) . '</pre>
</div>


Comes out as this:

VIEW SOURCE:
Array
(
    [3986] => Array
        (
            [id_work] => 3986
            [id_type] => etc etc etc etc
        )

)
<div class="works">
<pre>1</pre>
</div>



I'm having this problem repeatedly with every div I make and it's literally driving me INSANE and making it really really really really frustrating to dev on 2.1!!!!!!!!!!!!  >:( >:( >:( >:( >:( :'(
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

live627

Quote from: http://php.net/manual/en/function.print-r.phpIf you would like to capture the output of print_r(), use the return parameter. When this parameter is set to TRUE, print_r() will return the information rather than print it.

echo '
<div class="works">
<pre>' . print_r($context['works'], true) . '</pre>
</div>

Jade Elizabeth

I thought it would still work fine without that since I used pre tags?

Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Arantor

No, it's nothing to do with the fact you used pre_tags.

print_r without the true parameter will do the output, return nothing to the echo and then the echo will be processed, giving you the result you got.

Jade Elizabeth

Okay. I had this issue with my menu too, using a variable it wouldn't go in the right area and displayed above the div it should have been in. It's working now after fiddling but it wasn't before.

When it wasn't working I had something like <div id="works_menu">'; works_menu(); echo'</div> and it wouldn't put the menu inside the div. I moved the div inside of the function and now it works. That doesn't make any sense to me whatsoever.
Once proud Documentation Writer and Help Squad Leader | Check out my new adult coloring career: Color With Jade/Patreon.

Arantor

When you put it in an echo, in like echo 'thing', function(), 'thing'; it will evaluate the function before it does the rest of the echo because it has to evaluate everything before it can echo it.

Advertisement: