php,用函数调用替换文本
在我定制的 cms 中,我需要替换从数据库表中选择的部分文本,其中包含:
Lorem ipsum dolor sat amet, 精英脂肪组织 {块}'myfunc', 数组(11, '缩略图', '大', 18){/Block} sed do eiusmod tempor incididunt ut labore 伟大的痛苦
文本中带有 {Block} 的部分,应该替换为将执行函数 myfunc 的 php 函数,并传递包含上述数组的参数。
对我来说最大的问题是我不知道文本中有多少个{Block},以及它们将放置在哪里。
我知道我可以简单地“爆炸”文本,并做一些体操,但我不知道这是否是最好的方法。
我知道这并不简单......如果你能帮我,请。
先感谢您!
in my custom made cms, i need to replace part of the text that is selected from database table, that contains:
Lorem ipsum dolor sit amet,
consectetur adipisicing elit
{Block}'myfunc', array(11,
'thumbnail', 'large', 18){/Block} sed
do eiusmod tempor incididunt ut labore
et dolore magna aliqua
part of the text with {Block}, shoud be replaced with php function that will execute function myfunc, and pass parameters that contains mentioned array.
bigest problem for me is that i don't know how many {Block} i will have in text, and where they will be placed.
i know that i can simply "explode" text, and do some gymnastics, but i don't know if it is best way to it.
i know this is not simple one... if you can help me with it, please.
thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道,当我想用正则表达式做所有事情时,每个人都讨厌我,但我喜欢它:)
只是,一定要使用相同的分隔符分隔数组值,在我的情况下它只是逗号,在你的情况下,它是逗号+空格。随心所欲地调。
像这样的东西,可以很容易地被利用,所以,一定要检查 $match[1] 是否在你允许的函数列表中;)
I know, everybody hates me, when I want to do everything with regex, but I like it :)
Just, be sure to seperate array values with same seperators, in my case its just comma, in your case, it was comma + space. Tune whatever you like.
And stuff like this, can be easely exploited, so, be sure to check if $match[1] is in your allowed functions list ;)
你可以试试这个
You can try this