0

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

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by diafol
0

include.php

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

then in your main file:

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

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

0

Try this

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

//use

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

</div>

1

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;

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.