How to Embed PHP in HTML print

N

NickC

I am running a Python application under apache web server, executing as a
cgi script. Most of the output is print statements that write HTML.

I'd like to embed some PHP code within the HTML. The PHP is a gallery
plugin script that talks to the core photo gallery application, written in
php.

The idea is that my python app can display a random image from a photo
album, using the photo gallery application's plugin script.

If I do: 'print "<?php ... ?>"', it doesn't work. I imagine because the
web server never sees it as php code.

Is there a way to do this?

Some possible ideas:
Is there a way I can get python to call functions within a PHP app?
Perhaps write the plugin in a separate script in PHP, and include that
page within my output so that apache recognises the page inclusion? How
to get apache to pay attention to the output so it "wakes up" and does
some server-side includes?

Many thanks for any help.
 
N

NickC

content with ajax. Alternatively, use urllib in Python to retrieve a
page from the Apache server and insert that into its own output: that

Thanks for hint on urllib. I shake my head in amazement with python
sometimes. I'll write it here:

print urllib.urlopen('http://myserver.com/phpscript.php').read()

That's it. *One* line.

The output from the php script is:
<a href='zenphoto/kitty/IMG_0759.jpg' title='Random Picture...'>
<img src='zenphoto/cache/kitty/IMG_0759_800.jpg'
alt="random image"
IMG_0759" /></a>

and the one-liner seamlessly prints that to insert it into the html output.

And I thought it would be hard; I should have known better.
 
S

Steve Holden

NickC said:
Thanks for hint on urllib. I shake my head in amazement with python
sometimes. I'll write it here:

print urllib.urlopen('http://myserver.com/phpscript.php').read()

That's it. *One* line.

The output from the php script is:
<a href='zenphoto/kitty/IMG_0759.jpg' title='Random Picture...'>
<img src='zenphoto/cache/kitty/IMG_0759_800.jpg'
alt="random image"
IMG_0759" /></a>

and the one-liner seamlessly prints that to insert it into the html output.

And I thought it would be hard; I should have known better.
Always great to see Python doing impressive things for new users.

regards
Steve
 
S

Steve Holden

NickC said:
Thanks for hint on urllib. I shake my head in amazement with python
sometimes. I'll write it here:

print urllib.urlopen('http://myserver.com/phpscript.php').read()

That's it. *One* line.

The output from the php script is:
<a href='zenphoto/kitty/IMG_0759.jpg' title='Random Picture...'>
<img src='zenphoto/cache/kitty/IMG_0759_800.jpg'
alt="random image"
IMG_0759" /></a>

and the one-liner seamlessly prints that to insert it into the html output.

And I thought it would be hard; I should have known better.
Always great to see Python doing impressive things for new users.

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top