Jump to content

Putting some java inside PHP


86Stang

Recommended Posts

I'm trying to use a 3rd party app for commenting inside a PHP variable.

 

The app code I'm trying to include:

<script>
var idcomments_acct = '12345';
var idcomments_post_id;
var idcomments_post_url;
</script>
<script type="text/javascript" src="http://www.website.com/script.js"></script>

 

I'm trying to put it into a variable like:

$output .= "<script>";
$output .= "var idcomments_acct = '12345'\;";
$output .= "var idcomments_post_id\;";
$output .= "var idcomments_post_url\;";
$output .= "</script>";
$output .= "<script type=\"text/javascript\" src=\"http://www.website.com/script.js\"></script>";

 

and finally render it in the HTML by using:

<?php echo $output; ?>

 

 

I'm not getting any errors but nothing is showing up either.  Is this just basically not allowed, did I forget to escape something, is my approach all wrong, what?

Link to comment
https://forums.phpfreaks.com/topic/188103-putting-some-java-inside-php/
Share on other sites

first off, thats Javascript, not Java.

 

Secondly, that looks fine, but that javascript doesn't look like it will do anything (unless the external script does something) What do you expect it to do, and what is it actually doing. Have you looked in the error console to make sure there is no errors

 

Have you tried just putting the script directly in the HTML? I don't see why you are putting it in PHP in the first place.

 

 

on a second glance, you don't need to escape semi colons, so try removing the backslashes that are infront of the semi colons. That will cause a javascript syntax error

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.