PHP调用数组内的函数

时间:2018-04-10 01:38:23

标签: php function

我需要一些帮助。

我有一个简单的BBCODE preg_replace函数。当你引用一篇帖子时,我想称之为:

  

[QUOTE =帖子ID] [/ QUOTE]

但要做到这一点,我需要调用一个函数:quote_post($ id)

    function quote_post($id) {
    if($id){
    $postgrabid = $core->clean( $id );  
    $query = $db->query( "SELECT * FROM `forum_posts` WHERE `postid`='{$postgrabid}'");
    $array = $db->assoc( $query );
    echo $array['content'];
    } else {
        // Quotes without POSTID
    }
}

现在这是一个基本功能,因为它没有执行相关的权限检查(因为从技术上讲,你可以在论坛中引用任何帖子并查看它)。但是我想先了解一下我将如何做到这一点。

我的BBCode功能是:

    function bbc2html($content) {
  $search = array (
    '/(\[b\])(.*?)(\[\/b\])/',
    '/(\[B\])(.*?)(\[\/B\])/',
    '/(\[i\])(.*?)(\[\/i\])/',
    '/(\[I\])(.*?)(\[\/I\])/',
    '/(\[u\])(.*?)(\[\/u\])/',
    '/(\[U\])(.*?)(\[\/U\])/',
    '/(\[ul\])(.*?)(\[\/ul\])/',
    '/(\[li\])(.*?)(\[\/li\])/',
    '/(\[url=)(.*?)(\])(.*?)(\[\/url\])/',
    '/(\[url\])(.*?)(\[\/url\])/',
    '/(\[size=)(.*?)(\])(.*?)(\[\/size\])/',
    '/(\[SIZE=)(.*?)(\])(.*?)(\[\/SIZE\])/',
    '/(\[img\])(.*?)(\[\/img\])/',
    '/(\[IMG\])(.*?)(\[\/IMG\])/',
    '/(\[IMGR\])(.*?)(\[\/IMGR\])/',
    '/(\[imgr\])(.*?)(\[\/imgr\])/',
    '/(\[strike\])(.*?)(\[\/strike\])/',
    '/(\[STRIKE\])(.*?)(\[\/STRIKE\])/',
    '/(\[youtube\])(.*?)(\[\/youtube\])/',
    '/(\[YOUTUBE\])(.*?)(\[\/YOUTUBE\])/',
    '/(\[left\])(.*?)(\[\/left\])/',
    '/(\[LEFT\])(.*?)(\[\/LEFT\])/',
    '/(\[CENTER\])(.*?)(\[\/CENTER\])/',
    '/(\[center\])(.*?)(\[\/center\])/',
    '/(\[RIGHT\])(.*?)(\[\/RIGHT\])/',
    '/(\[right\])(.*?)(\[\/right\])/',
    '/(\[JUSTIFY\])(.*?)(\[\/JUSTIFY\])/',
    '/(\[justify\])(.*?)(\[\/justify\])/',
    '/(\[color=)(.*?)(\])(.*?)(\[\/color\])/',
    '/(\[COLOR=)(.*?)(\])(.*?)(\[\/COLOR\])/',
    '/(@\w+)/',
    '/(\[BADGE\])(.*?)(\[\/BADGE\])/',
    '/(\[badge\])(.*?)(\[\/badge\])/',
    '/(\[quote=)(.*?)(\])(.*?)(\[\/quote\])/',
    '/(\[QUOTE=)(.*?)(\])(.*?)(\[\/QUOTE\])/'
  );
  $replace = array (
    '<span style="font-weight: 700;">$2</span>',
    '<span style="font-weight: 700;">$2</span>',
    '<em>$2</em>',
    '<em>$2</em>',
    '<u>$2</u>',
    '<u>$2</u>',
    '<ul>$2</ul>',
    '<li>$2</li>',
    '<a href="$2" target="_blank">$4</a>',
    '<a href="$2" target="_blank">$4</a>',
'<span style="font-size: $2em!important;">$4</span>',
'<span style="font-size: $2em!important;">$4</span>',
    '<img src="$2" style="max-width: 100%;">',
    '<img src="$2" style="max-width: 100%;">',
    '<img src="$2" align="right">',
    '<img src="$2" align="right">',
    '<strike>$2</strike>',
    '<strike>$2</strike>',
    '<iframe width="500" height="315" src="http://www.youtube.com/embed/$2?modestbranding=1" frameborder="0"></iframe>',
    '<iframe width="500" height="315" src="http://www.youtube.com/embed/$2?modestbranding=1" frameborder="0"></iframe>',
    '<span class="left">$2</span>',
    '<span class="left">$2</span>',
    '<center$2</center>',
    '<center>$2</center>',
    '<span class="right">$2</span>',
    '<span class="right">$2</span>',
    '<span class="justify">$2</span>',
    '<span class="justify">$2</span>',
    '<span style="color: $2">$4</span>',
    '<span style="color: $2">$4</span>',
    '<span style="font-weight: 700;" class="onclick" onclick="profile(\'$1\')">$1</span>',
    '<div class="quest_badgedisplay"><img src="$2"></div>',
    '<div class="quest_badgedisplay"><img src="$2"></div>',
    'quote_post($2)',
    'quote_post($2)'
    );

  return preg_replace($search, $replace, $content);
}

非常感谢任何帮助!

0 个答案:

没有答案