课堂上的评价(包括)

时间:2016-05-16 08:48:16

标签: php preg-replace

在数据库表中的类get函数中,View::getContentByLink我想使用像'BB'这样的特殊代码。

[img=1,2,3,4,5] ==> $this->getIMG($1,$2,$3,$4,$5);

[inc=string] ==> include("string.php");

首先,我为preg_replace创建了一个函数(它正在工作):

private function showCodes($text) {
    $find = array(
        '~\[img=(.*?)\]~s',
        '~\[inc=(.*?)\]~s'
    );

    $replace = array(
        '<?php $this->getImg($1);?>',
        '<?php include("inc/$1.inc.php");?>'
    );

    return preg_replace($find,$replace,$text);
}

AND函数getContentByLink我这样做:

$str = "Just test with codes [inc=test_string] and pics [img=1,2,3,4,5]";

eval("?>\r\n $str \r\n<?php");
// This two are two different attempts I've tried
//eval("\$str = \"$str\";");
//eval("return $str");

View::getIMG函数正常工作,现在无关紧要。在此代码中,include('test_string.php')工作正常!但getImg不是。

var_dump返回:

  

View.class.php:74:string'只需用代码测试就可以了,并且pics getImg(1,2,3,4,5);?&gt;' (长度= 71)

返回的html源代码:

.(...)Just test with codes OK and pics <?php

也许使用$this是错误的..我尝试过使用$View(我在脚本中调用了这个变量)......

在类def脚本中使用eval运行imgGet函数还是在名为View类的main中运行?

0 个答案:

没有答案
相关问题