a strange question

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
gotornot
Forum Commoner
Posts: 54
Joined: Fri Jul 31, 2009 2:30 am

a strange question

Post by gotornot »

Hi

I wonder if anyone can help.
I am trying to create a script that will create a form dynamically then slot it into an html template where it says {SHOWFORM} the trouble is as with a simple string replace its great for using allready output code however this will call the template find the tag then replace it with the form.
Each template will be unique so it will be in a different place each time is there any easy way or shall i just bung it in a function and try the string replace thing?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: a strange question

Post by Christopher »

Use str_replace(). It will not matter where the tag to be replaces is in the template.
(#10850)
User avatar
JNettles
Forum Contributor
Posts: 228
Joined: Mon Oct 05, 2009 4:09 pm

Re: a strange question

Post by JNettles »

You could try Smarty, which is a pretty good templating system for PHP that can do like what you describe. If you don't want to go full-blown Smarty you can use substr to do the string replacement - in fact I have a note posted on the PHP manual substr page that does close to what you're asking for.

http://us3.php.net/manual/en/function.substr.php
Post Reply