![]() |
Replace place holder text with php script - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Replace place holder text with php script (/showthread.php?tid=51336) |
Replace place holder text with php script - El Forum - 04-30-2012 [eluser]jay2003[/eluser] Hi, Not sure iv described this properly but what im building a simple CMS and what im wanting to do is a user will enter ##GALLERY## or ##CONTACTFORM## (or whatever else i make available) into a tinymce editor in the place they want the item to appear on a particular page. I thought about usng the str_replace function to replace the placeholder with the code required for that particular item. Is that the best way to go about this? The photo gallery will be made up from a foreach loop... will I be able to get that to work with str_replace? Thanks in advance Jason Replace place holder text with php script - El Forum - 04-30-2012 [eluser]Stefan Hueg[/eluser] Hi, You could use the standard Codeigniter Parser to achieve what you want. Just call Code: $this->parser->set_delimiters('##', '##'); For more information: http://ellislab.com/codeigniter/user-guide/libraries/parser.html Replace place holder text with php script - El Forum - 04-30-2012 [eluser]jay2003[/eluser] Thanks for your reply. Ive looked at the documentation you suggested for the parser and cant see how I would make it work for what i'm trying to achieve. Any suggestions? Thanks Jason Replace place holder text with php script - El Forum - 04-30-2012 [eluser]Stefan Hueg[/eluser] [quote author="jay2003" date="1335819343"]Thanks for your reply. Ive looked at the documentation you suggested for the parser and cant see how I would make it work for what i'm trying to achieve. Any suggestions? Thanks Jason [/quote] Look at my post... $this->parser->set_delimiters() is not documented, that's why I've posted it to you. Code: $this->parser->set_delimiters($l_delim = '{', $r_delim = '}'); Just set your wanted delimiters (##). Replace place holder text with php script - El Forum - 04-30-2012 [eluser]jay2003[/eluser] Hi Stefan, Thanks for your reply. I am new to CI and PHP... Where would I then put my string and the code that I want to replace the bit inside the ## ## with? Thanks Jason Replace place holder text with php script - El Forum - 04-30-2012 [eluser]Stefan Hueg[/eluser] Here is an example: Code: function my_test() which should output "My content parser is just awesome!" In this example, $content is the variable where the content of your tinyMCE comes from and $replacements is the array with strings that should be replaced. So, if you have a variable like ##MYVAR## inside of your content, you'll have to add 'MYVAR' => 'my_replacement' to your $replacements-Array. Clear enough? Replace place holder text with php script - El Forum - 04-30-2012 [eluser]jay2003[/eluser] That looks great! Will give it a go this afternoon and let you know if i was sucessfull. Thanks for your help Jason Replace place holder text with php script - El Forum - 05-01-2012 [eluser]jay2003[/eluser] Thanks for your help with this it is working great thanks. Jason |