"Array" instead of the expected element

Hi,
I am trying to build a simple system for a client of mine that need to insert banner links on his website. The client, of course, has no experience on how to do it by code, so I am building my function on simple text files.

the function I built is:


<?php
function setBanner($position=False)
{
    if ($position=='left') {
        $file = 'sponsors/bannerLeft.txt';
        $lines = file( $file, FILE_SKIP_EMPTY_LINES );
        foreach ($lines as $line) {
            echo $line;
        }
    } elseif ($position=='right') {
        $file = 'sponsors/bannerRight.txt';
        $lines = file( $file, FILE_SKIP_EMPTY_LINES );
        foreach ($lines as $line) {
            echo $line;
        }
    } else {
        $file = 'sponsors/banners.txt';
        $content = file_get_contents( $file );
        $codes = explode( '###', $content );
        foreach ($codes as $code) {
            $lines = explode( '##', $code );
            $classes = array_slice( $lines, 0, 1 );
            $banner = array_slice( $lines, 1 );
            echo "<div class=\\"banner_" . $classes . " sponsor\\">\
";
            echo "<div class=\\"th\\">";
            echo "<div class=\\"tl\\"></div>";
            echo "<div class=\\"tr\\"></div>";
            echo "</div>";
            echo "<div class=\\"lv\\">";
            echo "<div class=\\"rv\\">";
            echo "<div class=\\"inner\\">";
            echo $banner;
            echo "<p>sponsor</p>";
            echo "</div>";
            echo "</div>";
            echo "</div>";
            echo "<div class=\\"bh\\">";
            echo "<div class=\\"br\\"></div>";
            echo "<div class=\\"bl\\"></div>";
            echo "</div>";
            echo "</div>";
        }
    }
}
?> 

while the text file banners.txt is something like:


left small
##
<a href="http:"><img src="http:" align="bottom" width="125" height="125" border="0" hspace="1" alt=""></a>
###
right small
##
<a href="http:"><img src="http:" align="bottom" width="125" height="125" border="0" hspace="1" alt=""></a>

I am getting a strange behavior I am not able to understand, i.e. instead of the expected text for classes and the banner link, I only got the word “Array” for both.

I am sure it is a newbie error, so thanks in advance for your help.

$banner = array_slice( $lines, 1 );

echo $banner;

array_slice returns an array, so that’s what you will get when you echo. echo $banner[0] will prob fix it.

Doh…!
What an idiot, it’s clear I was tired. :stuck_out_tongue:
I am at home, now, but I am sure that is the problem. A soon I come back to the office I will fix it.

Thanks a lot.

p.s.
Btw, may I ask you, if you have a minute, how do you find the code? How could I improve it?