How do I include a PHP function in an .shtml file?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stricklin
Forum Newbie
Posts: 3
Joined: Wed May 14, 2003 6:46 pm
Location: Shreveport, LA

How do I include a PHP function in an .shtml file?

Post by Stricklin »

I'd like to include a PHP4 function in my index.shtml page, but everytime I place the function within the <HEAD></HEAD> section as I'm told, the function appears as text at the top of my page.

I'm told that I have to use the .shtml extension if I'm to have the server-side include in my index page execute, and I'm told that any PHP code must be in a page having the .php4 extension. But what if I want both?

Some in the Movable Type Support Forum have suggested that "There's some sort of declaration (similar to a script declaration for javascript)."

Does such a declaration exist? If not, can anyone advise further? :?:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

there's a <!--#exec cmd=...> command for SSI. If your provider allows that you might call php as cgi and have a script executed.

the php-module for apache2 is implemented as filter. This openes some new features (or makes them available easier). You can have multiple handlers for one document, passing the source/output-stream through each filter.
Let's say PHP is the first handler, not only get's your source parsed and executed as php-script before SSI takes place, the script might also add new <!-- #SSI command --> lines to the output stream. SSI will parse them. Groovy, isn't it ;)
Gleeb
Forum Commoner
Posts: 87
Joined: Tue May 13, 2003 7:01 am
Location: UK
Contact:

Post by Gleeb »

If you're using SHTML purely to include other files, you might want to look into include()
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post by []InTeR[] »

Gleeb wrote:If you're using SHTML purely to include other files, you might want to look into include()
PHP cannot be used in the SHTML file.

You have to include a php file with Server Side Includes.
Gleeb
Forum Commoner
Posts: 87
Joined: Tue May 13, 2003 7:01 am
Location: UK
Contact:

Post by Gleeb »

I was indicating that if you're using SHTML just for incuding other files, you might want to replace it all with include(), or, come to think of it, readfile()

This allows you to use PHP and still get the same effects as SHTML :)

Edit: BBCode markup fix ... additional edit: if you can read this without a loupe your monitor is too large.... sorry, couldn't resist, volka
Stricklin
Forum Newbie
Posts: 3
Joined: Wed May 14, 2003 6:46 pm
Location: Shreveport, LA

Include() works great

Post by Stricklin »

Just a note to you guys to tell you that Include() worked perfectly and to thank everyone who weighed in to help. If you want to see the results, visit my page at http://www.charlesstricklin.com/
Post Reply