Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
txp:php wrapping code with doctype declaration etc
I’m using the following in a Page (template) to call and output some code from an external source;
<txp:php>
webDoc = DOMDocument::loadHTMLFile("http://shop.proplaster.com.au/pages/specials");
print $webDoc->saveHTML();
</txp:php>
This works perfectly except TXP is wrapping the code output in the following;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body>
—correct code
</body></html>
I’m using version 4.0.6 and due to certain plugins etc in use, an upgrade to a newer version is currently out of the question.
I have TXP set to allow PHP in Pages – even when I’ve switched to allowing raw PHP and dispensed with the txp:php tage I get the same results.
Diagnostics are saying PHP: 5.2.12 and MySQL: 5.0.81
Its doing the same under MAMP and on a hosted server so I dont think its a server issue.
Any ideas folks?
Last edited by damienbuckley (2010-01-29 06:00:57)
Offline
Re: txp:php wrapping code with doctype declaration etc
damienbuckley wrote:
This works perfectly except TXP is wrapping the code output in the following;
TXP ain’t wrapping anything ;)
Any ideas folks?
It happens because that is what saveHTML
and loadHTML
do together. The DOMDocument is used specifically to build new documents and that is what it well… did. It may be a bug in DOMDocument (well, it is), but it still does it. You can call it a feature ;)
You can either strip the added content from the output, or you can use good and old file_get_contents()
and such.
Offline
Re: txp:php wrapping code with doctype declaration etc
Thanks for the reply.
I’m no programmer – someone else set this up for me to pull content from the hosted e-commerce site onto the front page of the TXP site to save on content duplication. The script doesn’t do this in anything other than Textpattern…
Do you have an alternate suggestion?
Offline
Re: txp:php wrapping code with doctype declaration etc
Thanks for the help – with a bit of playing around I got it working ok (sans additional elements) using;
<txp:php>
$webDoc = file_get_contents("http://shop.proplaster.com.au/pages/specials");
print $webDoc;
</txp:php>
Offline