View Full Version : posting PHP code in a javascript header

03-01-2008, 05:23 AM
I am trying to post PHP code in a javascript header

here is an example of PHP code:

foreach ($feed->get_items() as $item){

<p><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></p>
<?php echo $item->get_content(); ?>
<p>Source: <a href="<?php $feed = $item->get_feed(); echo $feed->get_permalink(); ?>"><?php $feed = $item->get_feed(); echo $feed->get_title(); ?></a></p>

now how would I get that code to displa in something like:

Header("content-type: application/x-javascript");
echo "document.write(\"output the above code into here \")"; // how do I do this?

03-01-2008, 05:28 AM
header("content-type: application/x-javascript");
foreach ($feed->get_items() as $item){
document.write('<p><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></p>');
document.write('<?php echo $item->get_content(); ?>');
document.write('<p>Source: <a href="<?php $feed = $item->get_feed(); echo $feed->get_permalink(); ?>"><?php $feed = $item->get_feed(); echo $feed->get_title(); ?></a></p>');
Though why would you be outputting this with JS rather than php?

03-01-2008, 05:32 AM
I am using this as a server side script to display text and images on other websites (cut and paste code for external users to use on their site)

so JS is the way to go

thanks by the way!