PHP — how to customize the template to load the right code?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
3 views
have text for example
$text="blah blah {foto:::37} blah blah blah {video:::82}";

need the text to transform
$text="blah blah blah <?$modulid=37;include('mods/foto.php');?> blah blah blah <?$modulid=82;include('mods/video.php');?>";
by | 3 views

2 Answers

0 like 0 dislike
I think you need to act differently.
Looking for first curly brace in the text - $p1 = strpos($text, '{');
Then the closing - $p2 = strpos($text, '}');
Get what is in between - $key = substr($text, $p1+1, $p2-$p1-1); //here can be a mistake
Searching for arguments - $args = explode(':::', $key);
Then - $modulid=$args[1];
Need a downloadable file or $file = include('mods/'.$args[0].'.php');
And replace in template $text = str_ireplace('{'.$key.'}', $file, $text);

But then you need to be careful. Can come across a brace that is not template variable, so people usually use double curly brackets. Above all that it is not the fact that correct, but roughly the gist, I hope.
by
0 like 0 dislike
Suggest to read about regular expressions :)
by

Related questions

0 like 0 dislike
1 answer
asked Apr 9, 2019 by vladislavignatyev
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
28,151 users