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? Link to comment https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/ 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. Link to comment https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/#findComment-1029310 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 ';'" Link to comment https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/#findComment-1029314 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. Link to comment https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/#findComment-1029315 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? Link to comment https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/#findComment-1029316 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. Link to comment https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/#findComment-1029317 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? Link to comment https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/#findComment-1029319 Share on other sites More sharing options...
Sware Posted March 20, 2010 Author Share Posted March 20, 2010 Anyone? Link to comment https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/#findComment-1029326 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. Link to comment https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/#findComment-1029341 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? Link to comment https://forums.phpfreaks.com/topic/195960-javascript-working-with-php/#findComment-1029342 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.