Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-07-09 13:26:39

driz
Member
From: Huddersfield, UK
Registered: 2008-03-18
Posts: 441
Website

PHP not working?

Is their any reason why this PHP code will not run in Txp?

The echo test runs fine, but the quote bit won’t run? Is their something about it Txp dislikes?

<txp:php>
function testimonials() {
	$quotes = array("One", "Two", "Three", "Four", "Five", "Six");
	$title = $quotes[array_rand($quotes)];
	echo "Testing PHP works on my site";
	}
testimonials();
</txp:php>

~ Cameron

Offline

#2 2008-07-09 13:41:02

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: PHP not working?

You’re not echoing $title. When the <txp:php> block ends, $title is no longer defined (declare it global if that’s what you want).

Offline

#3 2008-07-09 13:42:36

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: PHP not working?

You actually have to call $title ;).

echo "Testing PHP works on my site {$title}";

Edit: Ruud beat me to it :).

Last edited by jm (2008-07-09 13:43:21)

Offline

Board footer

Powered by FluxBB