2017-01-04 6 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] [/ TEX] 태그의 모든 </br>을 삭제합니다. 내같은 regexp 수정하려면 피곤하지만 작동하지 않습니다. 이^

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

같은

+0

내 짧은 코드 라이브러리를 사용해주세요. https://github.com/thunderer/Shortcode? 단축 코드를 처리하는 데 많은 시간을 절약 할 수 있습니다. –

답변

0

시도 뭔가가 return 문 앞에 코드의 평화를 추가합니다.

+0

고맙습니다! – Maxim