Jump to content

Recommended Posts

Bascially I have a Javascript script that has to have PHP elements in it. When I try to echo it all it doesn't work, and when I put PHP in the variable it still doesnt work.. Any luck?

 

This is what I currently have..

<?php
echo "var pausecontent=new Array()";
echo "pausecontent[0]='$rssticker->recent-post->subject'";
echo "pausecontent[1]='<a href='#'>New Divisions Launched</a> - <i>7 Hours Ago</i>'";
echo "pausecontent[2]='<a href='#'>Welcome New Leaders</a> - <i>20 Hours Ago</i>'";
?>

I tried it this way also.

pausecontent[0]='<?php $rssticker->recent-post->subject ?>';

 

No worky. Any suggestions?

Link to comment
https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/
Share on other sites

Bascially I have a Javascript script that has to have PHP elements in it. When I try to echo it all it doesn't work, and when I put PHP in the variable it still doesnt work.. Any luck?

 

This is what I currently have..

<?php
echo "var pausecontent=new Array()";
echo "pausecontent[0]='$rssticker->recent-post->subject'";
echo "pausecontent[1]='<a href='#'>New Divisions Launched</a> - <i>7 Hours Ago</i>'";
echo "pausecontent[2]='<a href='#'>Welcome New Leaders</a> - <i>20 Hours Ago</i>'";
?>

I tried it this way also.

pausecontent[0]='<?php $rssticker->recent-post->subject ?>';

 

No worky. Any suggestions?

 

<?php
echo "var pausecontent=new Array()";
echo "pausecontent[0]='". $rssticker->recent-post->subject . "'";
echo "pausecontent[1]='<a href='#'>New Divisions Launched</a> - <i>7 Hours Ago</i>'";
echo "pausecontent[2]='<a href='#'>Welcome New Leaders</a> - <i>20 Hours Ago</i>'";
?>

 

Doesn't JS need a semicolon thought? You only end the line in a single quote it seems. Make sure $rssticker->recent-post->subject is a string.

I changed to this..

 

<?php
echo "var pausecontent=new Array();";
echo "var rsstxt=" . $rssticker->recent-post->subject . ";";
echo "pausecontent[0]='rsstxt';";
echo "pausecontent[1]='<a href='#'>New Divisions Launched</a> - <i>7 Hours Ago</i>';";
echo "pausecontent[2]='<a href='#'>Welcome New Leaders</a> - <i>20 Hours Ago</i>';";
?>

 

Now i'm getting "Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';'"

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.