preg_replace 为 php 代码
我有一个函数可以找到正则表达式,然后用 php 代码替换。我想让它在屏幕上用 php 代码替换找到的正则表达式,就像让它回显“。除非它回显源代码中的内容,否则它会显示所有 标签并回显以及所有内容,并且不只是输出“wat”。我不会用“wat”一词替换文本,因为这不是我想要做的,你知道如何解析我替换它的php吗
$this->template = preg_replace("/<!-- IF (.*?)? ?-->/","<?php\nif($1) {",$this->template);
?也是 ENDIF,如果条件为真,则以 } ?> 结束它,中间的内容就是输出。
I have a function that finds a regex thingy, then replaces with php code. I want to have it replace the found regex with php code on the screen, like have it echo out ". except when it echos that in the source, it shows all the <?php
tags and echo and everything, and doesnt just output 'wat'. no im not going to just replace the text with the word 'wat' because that is not what im trying to do. do you know how to parse the php i replace it with?
$this->template = preg_replace("/<!-- IF (.*?)? ?-->/","<?php\nif($1) {",$this->template);
there is also and ENDIF which closes it with } ?>
. the content in between is the output if the condition is true.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许你需要的是 eval() http://php.net/manual/en/ function.eval.php
Maybe what you need is eval() http://php.net/manual/en/function.eval.php