Sware Posted March 20, 2010 Share Posted March 20, 2010 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? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted March 20, 2010 Share Posted March 20, 2010 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. Quote Link to comment Share on other sites More sharing options...
Sware Posted March 20, 2010 Author Share Posted March 20, 2010 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 ';'" Quote Link to comment Share on other sites More sharing options...
oni-kun Posted March 20, 2010 Share Posted March 20, 2010 "$rssticker->recent-post->subject" doesn't return anything that can be plugged into a string. Quote Link to comment Share on other sites More sharing options...
Sware Posted March 20, 2010 Author Share Posted March 20, 2010 "$rssticker->recent-post->subject" doesn't return anything that can be plugged into a string. I don't think I understand? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted March 20, 2010 Share Posted March 20, 2010 Run: print var_dump($rssticker->recent-post->subject); and see what it returns, it is most likely an object and not what you can display in a string like you are trying to do, that is why you get the parse error. Quote Link to comment Share on other sites More sharing options...
Sware Posted March 20, 2010 Author Share Posted March 20, 2010 I don't think it works, it doesn't display anything.. How do I fix it? Quote Link to comment Share on other sites More sharing options...
Sware Posted March 20, 2010 Author Share Posted March 20, 2010 Anyone? Quote Link to comment Share on other sites More sharing options...
oni-kun Posted March 21, 2010 Share Posted March 21, 2010 Anyone? If nothing is displayed, then $rssticker->recent-post->subject does not return a value. It is an object method. You cannot print it in that manner. Quote Link to comment Share on other sites More sharing options...
Sware Posted March 21, 2010 Author Share Posted March 21, 2010 Is there a way to make that PHP rss feed into a Javascript Variable then? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.