Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-01-2008, 04:23 AM   PM User | #1
Bobafart
Regular Coder

 
Join Date: Dec 2006
Posts: 416
Thanks: 168
Thanked 1 Time in 1 Post
Bobafart is on a distinguished road
posting PHP code in a javascript header

I am trying to post PHP code in a javascript header

here is an example of PHP code:
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:

Code:
Header("content-type: application/x-javascript"); 
echo "document.write(\"output the above code into here \")";   // how do I do this?
Bobafart is offline   Reply With Quote
Old 03-01-2008, 04:28 AM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
PHP Code:
<?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?
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Users who have thanked _Aerospace_Eng_ for this post:
Bobafart (03-01-2008)
Old 03-01-2008, 04:32 AM   PM User | #3
Bobafart
Regular Coder

 
Join Date: Dec 2006
Posts: 416
Thanks: 168
Thanked 1 Time in 1 Post
Bobafart is on a distinguished road
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!
Bobafart is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:42 AM.


Advertisement
Log in to turn off these ads.