convert javascript to PHP function
<p>I would like to convert this javascript (which works correctly) into a PHP function, so that all this code does not have to appear in the source code of the webpage.</p>

<pre><code>&lt;script type="text/javascript"&gt;

    var images = [],
    index = 0;

    images[0] = "&lt;a href = 'http://www.random_target1.com' target='_blank'&gt;&lt;img src='//www.random_target1.com/random_banner.jpg' width='120' /&gt;&lt;/a&gt;";

    images[1] = "&lt;a href = 'http://www.random_target2.com' target='_blank'&gt;&lt;img src='//www.random_target2.com/random_banner.jpg' width='120' /&gt;&lt;/a&gt;";

    images[2] = "&lt;a href = 'http://www.random_target3.com' target='_blank'&gt;&lt;img src='//www.random_target3.com/random_banner.jpg' width='120' /&gt;&lt;/a&gt;";

    index = Math.floor(Math.random() * images.length);
    document.write(images[index]);

&lt;/script&gt;
</code></pre>

<p>I tried this PHP function in the PHP file, and thought I could call its result, from the HTML file, so only determined value would appear in HTML source code. This code broke the page, though.</p>

<pre><code>public function getRandom()
{
    $images = array();
    $index = 0;

    $images[0] = "&lt;a href = 'http://www.random_target1.com' target='_blank'&gt;&lt;img src='//www.random_target1.com/random_banner.jpg' width='120' /&gt;&lt;/a&gt;";

    $images[1] = "&lt;a href = 'http://www.random_target2.com' target='_blank'&gt;&lt;img src='//www.random_target2.com/random_banner.jpg' width='120' /&gt;&lt;/a&gt;";

    $images[2] = "&lt;a href = 'http://www.random_target3.com' target='_blank'&gt;&lt;img src='//www.random_target3.com/random_banner.jpg' width='120' /&gt;&lt;/a&gt;";

    $index = Math.floor(Math.random() * $images.length);
    return $images[$index];
}   
</code></pre>
