Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP正则表达式-删除所有<;br>;标签_Php_Regex_Bbcode - Fatal编程技术网

PHP正则表达式-删除所有<;br>;标签

PHP正则表达式-删除所有<;br>;标签,php,regex,bbcode,Php,Regex,Bbcode,我有一个函数 function showBBcodes($text) { // BBcode array $find = array( '~\[b\](.*?)\[/b\]~s', '~\[i\](.*?)\[/i\]~s', '~\[u\](.*?)\[/u\]~s', '~\[quote\](.*?)\[/quote\]~s', '~\[size(.*?)\=(.*?)\](.*?)\[/size\]~s', '~\[color

我有一个函数

    function showBBcodes($text) {
  // BBcode array
  $find = array(
    '~\[b\](.*?)\[/b\]~s',
    '~\[i\](.*?)\[/i\]~s',
    '~\[u\](.*?)\[/u\]~s',
    '~\[quote\](.*?)\[/quote\]~s',
    '~\[size(.*?)\=(.*?)\](.*?)\[/size\]~s',
    '~\[color(.*?)\=(.*?)\](.*?)\[/color\]~s',
    '~\[url\]((?:ftp|https?)://.*?)\[/url\]~s',
    '~\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]~s',
    '~\[b_id\](.*?)\[/b_id\]~s',
    '~\[tex\](.*?)\[/tex\]~s',
    '~\[sup\](.*?)\[/sup\]~s'
  );
  // HTML tags to replace BBcode
  $replace = array(
    '<span stype="font-weight: bold;">  $1</span>',
    '<i>$1</i>',
    '<span style="text-decoration:underline;">$1</span>',
    '<pre>$1</'.'pre>',
    '<span style="font-size:$2px;">$3</span>',
    '<span style="color:$2;">$3</span>',
    '<a class="blue-font" href="$1">$1</a>',
    '<a class="blue-font" href="$1"><img src="$1" alt=""></a>',
    '<sub>$1</sub>',
    '<a class="blue-font" href="http://jabber.pozitiv-r.ru/cgi-bin/mathtex.cgi?$1"><img src="http://jabber.pozitiv-r.ru/cgi-bin/mathtex.cgi?$1" alt=""></a>',
    '<sup>$1</sup>'
  );
  // Replacing the BBcodes with corresponding HTML tags
  return preg_replace($find,$replace,$text);
} 
函数showBBcodes($text){
//BBcode数组
$find=数组(
“~\[b\](.*?\[/b\]~s”,
“~\[i\](.*?\[/i\]~s”,
“~\[u\](.*?\[/u\]~s”,
“~\[quote\](.*?\[/quote\]~s”,
“~\[size(.*?\=(.*?\])(.*?\[/size\]~s”,
“~\[color(.*?\=(.*?\])(.*?\[/color\]]s”,
“~\[url\]((?:ftp | https?)://.*?\[/url\]~s”,
“~\[img\](https?:/.*?)(?:jpg | jpeg | gif | png | bmp))\[/img\]~s”,
“~\[b\u id\](.*)\[/b\u id\]~s”,
“~\[tex\](.*?\[/tex\]~s”,
“~\[sup\](.*)\[/sup\]~s”
);
//替换BBcode的HTML标记
$replace=数组(
'  $1',
'$1',
'$1',
'$1',
'$3',
'$3',
'',
'',
'$1',
'',
'$1'
);
//用相应的HTML标记替换BBCODE
返回preg_replace($find,$replace,$text);
} 

我只需要从[tex][/tex]标签中删除所有

。我很想修改我的regexp,比如
^#s
,但它不起作用。

试试这样的方法^

$text=preg\u replace\u回调(
“~\[tex\].*?\[/tex\]~s”,
函数($matches){
返回preg_replace(“~~”,“$matches[0]);
},
$text
);

return
语句之前添加代码的和平。

试试这样的方法^

$text=preg\u replace\u回调(
“~\[tex\].*?\[/tex\]~s”,
函数($matches){
返回preg_replace(“~~”,“$matches[0]);
},
$text
);

return
语句之前添加代码和平。

您能试试我的快捷码库吗:?这将为您节省大量处理短代码的时间。您能试试我的短代码库吗:?它将为您节省大量处理短代码的时间。
$text = preg_replace_callback(
    '~\[tex\].*?\[/tex\]~s',
    function ($matches) {
        return preg_replace('~<br.*?>~', '', $matches[0]);
    },
    $text
);