Hi,

I have an unordered list in a file called elements.

is there any way of putting the unordered list into a variable so that i can use include to place it on my homepage?

help would be appreciated
thanks

Member Avatar
diafol

include.php

<ul id="list">
    <li>one</li>
    <li>two</li>
    <li>three</li>
</ul>

then in your main file:

...
include('include.php');
...

Thank you, is there any way of storing this list in a variable and echo it onto the main file page so i can write another ul in the include.php page?
thanks for your reply

Try this

$variable='<ul id="list">'.
    '<li>one</li>'.
    '<li>two</li>'.
    '<li>three</li>'.
    '</ul>';

//use

<div>
<?php echo $variable;?>

</div>

Member Avatar
diafol

Hmmm. Thought I edited my post obviously not :(

$el = '<ul id="list">
    <li>one</li>
    <li>two</li>
    <li>three</li>
</ul>';

then in your main file:

...
include('include.php');
...
echo $el;

You can prettify the html output with n and t or use the heredoc / newdoc syntax

Here's newdoc:

$el = <<<'EOT'
    <ul id="list">
        <li>one</li>
        <li>two</li>
        <li>three</li>
    </ul>
EOT;