2017-01-04 10 views
1

私は機能PHP正規表現 - すべて<br>タグを削除します

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); 
} 

を持って、私は必要なのは[TEX] [/テックス]タグからすべての</br>を削除しています。 ^<br.*?>#sのような正規表現を修正するのは疲れましたが、うまくいきません。

+0

私のショートコードライブラリを試してください:https://github.com/thunderer/Shortcode?ショートコードを処理する時間を節約できます。 –

答えて

0

returnステートメントの前にコードの平和を追加します。このような何か^

$text = preg_replace_callback(
    '~\[tex\].*?\[/tex\]~s', 
    function ($matches) { 
     return preg_replace('~<br.*?>~', '', $matches[0]); 
    }, 
    $text 
); 

を試してみてください。

+0

ありがとうございます! – Maxim

関連する問題