How do I embed php into blogger?
October 17, 2008 12:16 PM   Subscribe

Is there a way to embed php into a blogger template?

It seems like the tags are getting stripped out before it gets to my site. Do I need to somehow escape the php code so the Blogger parser just skips those tags prior to publishing? I have already written the code that generates the html I want as a standalone php page (and as a perl script if that helps).
posted by mzurer to Computers & Internet (7 answers total) 1 user marked this as a favorite
 
Response by poster: Oh - I am publishing to a custom domain via ftp.
posted by mzurer at 12:17 PM on October 17, 2008


I'm not sure, but I doubt this is possible with Blogger, mostly because it doesn't make much sense to do something like that with Blogger. If you can write PHP and your host supports PHP, why wouldn't you use a Blog tool written in PHP, e.g. WordPress, Drupal, etc.?
posted by scottreynen at 12:47 PM on October 17, 2008


Response by poster: I'm just trying to get one feature in that doesn't seem possible with the blogger tools. I may yet switch to another platform, but if this worked, I wouldn't really need to, and I could offload maintenance back to the actual author.
posted by mzurer at 1:16 PM on October 17, 2008


If the box containing the content you need to generate with php has a somewhat predictable size, I would consider using an iframe with src attribute pointing at the php script on your server.

Re: escaping: I don't think think there's anyway you could escape <?php that would both be allowed by blogger and parsed as php on the server ... you would have to do some sort of string replacement. Use something like ###?php and ?!!! and write a little command line script that recurses through the directories that get ftp'd and replaces those strings with the php open and close tags with sed or something. That could get pretty hairy, though, if you (the person with shell access {do you have shell access?}) aren't the author. E.g. how would the process of substitution be triggered? A cronjob would be overkill it seems. Maybe if the script was smart enough to only run sed on files on that been touched recently? Still, on a large blog, just recursing through the dirs could be expensive.
posted by and hosted from Uranus at 1:45 PM on October 17, 2008


Why don't you just add the PHP to the standalone php page?
posted by oulipian at 2:03 PM on October 17, 2008


Here's a somewhat complex work-around:

Add something like <div id="php-replace"></div> to your template as a marker where you want the PHP to go. Then make a PHP script that takes a path, finds the file on that path, and replaces the marker with the PHP. Then make a mod_rewrite rule that sends all requests as paths to that PHP script.

Another potential option: use client-side JavaScript instead. That may not work with what you're doing; I have no idea what you're doing.
posted by scottreynen at 6:50 PM on October 17, 2008


Response by poster: I am trying to get an index of all the posts on every page. This is super easy to parse from the feed, whereas the template tags don't seem to have access to all posts in all contexts. Javascript is probably the answer.
posted by mzurer at 8:42 PM on October 17, 2008


« Older How much is an Andreas Gursky?   |   Grandmother will trade Pot Roast for Political... Newer »
This thread is closed to new comments.