...

View Full Version : posting PHP code in a javascript header



Bobafart
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){

?>
<div>
<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>
</div>
<?php
}


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?

_Aerospace_Eng_
03-01-2008, 05:28 AM
<?php
header("content-type: application/x-javascript");
foreach ($feed->get_items() as $item){
?>
document.write('<div>');
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>');
document.write('</div>');
<?php
}
Though why would you be outputting this with JS rather than php?

Bobafart
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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum