Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

  1. Index
  2. » How do I…?
  3. » Php include

#1 2008-10-28 15:14:55

Nonsense
Member
Registered: 2005-11-25
Posts: 53

Php include

I tried searching the forum for solution on this but couldn’t find any obvious answers (and yes, I have activated php-support in pages) so here it goes:

I’m trying to include a text from a php or text-file:

<txp:php>include 'http://www.domain.name/folder/title.php'; </txp:php>

The file “title.php” conatins the following:

Title

That didn’t work though.

I just want a quick and easy way to include a text from either a php or text-file on my server.

Last edited by Nonsense (2008-10-28 15:17:24)

Offline

#2 2008-10-29 08:57:47

wet
Developer Emeritus
From: Schoerfling, Austria
Registered: 2005-06-06
Posts: 3,330
Website Mastodon

Re: Php include

Use the proper file path, not the URL.

E.g.

<txp:php>include ('/webroot/folder/title.php'); </txp:php>

Offline

#3 2008-10-29 11:15:51

Nonsense
Member
Registered: 2005-11-25
Posts: 53

Re: Php include

That did the trick!

I used the tab described by the team at Textpattern to get the path:

<txp:php>var_dump(getcwd(), get_include_path());</txp:php>

http://textpattern.com/faq/34/how-do-i-use-php-code

The only this was that when I used that snippet I got quite a lot of alternatives to choose from.
So I broke the script as:

<txp:php>get_include_path());</txp:php>

Which gave me an error, but also a reference to the php path.

Offline

#4 2008-10-29 12:25:37

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Php include

Which gave me an error, but also a reference to the php path.

Quite obvious, ‘cause there is a typo, extra ) at the ending…

Offline

#5 2008-10-29 14:56:33

Nonsense
Member
Registered: 2005-11-25
Posts: 53

Re: Php include

Ah.
Quite right.

Offline

#6 2008-10-29 16:21:42

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Php include

Isn’t that path information simply available from Txp’s Diagnostics tab?

Offline

#7 2008-10-29 16:42:55

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Php include

masa wrote:

Isn’t that path information simply available from Txp’s Diagnostics tab?

Yep, is. And in config, database and so on. And it isn’t even required always (dots, slashes – we love them). We even got defined txpath etc.

And to add, if it’s only text file with out any PHP code, we shouldn’t/have to even use include. readfile, file_get_contents and other file functions are for that purpose.

Last edited by Gocom (2008-10-29 16:43:21)

Offline

#8 2008-10-29 18:41:20

Nonsense
Member
Registered: 2005-11-25
Posts: 53

Re: Php include

Oh.
I feel stupid now.

Offline

#9 2008-10-29 18:51:46

masa
Member
From: Asturias, Spain
Registered: 2005-11-25
Posts: 1,091

Re: Php include

Nonsense wrote:

I feel stupid now.

Nah, no need – welcome to the club! :-)

Offline

  1. Index
  2. » How do I…?
  3. » Php include

Board footer

Powered by FluxBB