views:

62

answers:

1

Hey All

I have the following code (PHP):

  $link = array(
    "<ul>
          <li><a href="index.html" class="active">Home</a></li>
          <li><a href="whatwedo.html">What We Do</a></li>
          <li><a href="howitworks.html">How It Works</a></li>
          <li><a href="support.html">Support</a></li>
          <li><a href="lalalala_hiding_paypal_url_details">Sign Up</a></li>
          <li><a href="contact.php">Contact Us</a></li>
        </ul>",
    "<p>hi</p>",
    "<img src="images/illy.png" />",
    "<a href="index.html">go to index</a>",
    "<h3>blah</h3>",
    "<p>yipeeeeeeeee!</p>");

    // Choose a random piece.
    $i = sizeof($link);
    srand((double)microtime()*1000000);

    // Show random piece.
    $result = $link[rand(0,$i - 1)];

The above is inside a PHP file.

I have another file (HTML File) which includes:

<script type='text/javascript' src='http://website.net/myphpfile.php'&gt;
</script>

And I would like to display in pure javascript the $result of the PHP function where ever the javascript scripts tags are placed.

Is there anyway I can do this easily?

Thank you

A: 

Just make myphpfile.php echo javascript code.

echo "var x=171;";
echo "alert(x+' the number');";

OR

$js=<<<JAVASCRIPT
var t=10100;
alert(t);
JAVASCRIPT;
echo $js;
Itay Moav
huh..? why not just `?>var t=10100; alert(t);<?php`? Why mess around with strange constructs for something PHP was designed to do?
roe
None of that code actually works. :(
lucifer
@j-t-s: try it this way: `<?php echo "alert($result);" ?>`
prodigitalson
doesn't alert display a messagebox? would document.write work that way too? (thank you)
lucifer
Still nothing with "alert($result);".
lucifer
@j-t-s: yes alret displays a box. We dont really know how you want to use the data youre writing out so alert is a generic example that lets you see if the data or whatever is there for use. You would most likely replace this with a simple `var fromPhp = thephpvalue;` or a function call or something. no document.write will write whatever to the document as its name implies. You are jsut sticking this php code on to the end of the file you quoted in your question as opposed to replacing it all, right?
prodigitalson