Welcome Guest, Not a member yet? Register   Sign In
Replace place holder text with php script
#1

[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





#2

[eluser]Stefan Hueg[/eluser]
Hi,

You could use the standard Codeigniter Parser to achieve what you want. Just call
Code:
$this->parser->set_delimiters('##', '##');
$this->parser->parse_string(...);

For more information: http://ellislab.com/codeigniter/user-gui...arser.html
#3

[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
#4

[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 (##).
#5

[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
#6

[eluser]Stefan Hueg[/eluser]
Here is an example:
Code:
function my_test()
{
  $this->load->library('parser');
  $content = 'My content parser is just ##PLACEHOLDER##';
  $this->parser->set_delimiters('##', '##');
  
  $replacements = array(
   'PLACEHOLDER' => 'awesome!'
  );
  
  $output = $this->parser->parse_string($content, $replacements, TRUE);
  echo $output;
}

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?
#7

[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
#8

[eluser]jay2003[/eluser]
Thanks for your help with this it is working great thanks.

Jason




Theme © iAndrew 2016 - Forum software by © MyBB