many thanks, and kudos for the quick reply. i will try that right away!

as a sub-question, do you mind telling me where you learned regexp? i've been 
searching google all day with no luck, i've just find more or less basic regexp 
guides. did you learn through practice or do you have a secret source? ;-)

On Tue, 12 Nov 2002 18:35:55 +0100
[EMAIL PROTECTED] (Ernest E Vogelsinger) wrote:

>At 17:49 12.11.2002, Gustaf Sjoberg spoke out and said:
>--------------------[snip]--------------------
>>Hi,
>>i'm trying to replace every instance of "<br>" within the "<pre>..</pre>" 
>>tags. i want all other breakrows to remain the same.
>>
>>i've tried numerous regular expressions, but i can't find a way to just 
>>replace the breakrows.. it replaces _everything_ bewteen <pre> and </pre>.
>--------------------[snip]-------------------- 
>
>You need a two-phase operation on this:
>
>1) isolate all <pre></pre> elements
>   preg_match('/(.*?)<pre>(.*?)<\/pre>(.*)/is', $string, $armatch);
>
>$armatch now contains:
>   [0] all, ignore this
>   [1] everything before <pre>
>   [2] everything within <pre></pre>
>   [3] the rest after </pre>
>
>2) go on and replace all <br>'s here:
>   preg_replace('/<br>\n?/is', "\n", $armatch[2]);
>
>The whole stuff would look something like
>
>/* UNTESTED */
>function kill_br_within_pre($string)
>{
>    $re1 = '/(.*?)<pre>(.*?)<\/pre>(.*)/is';
>    $re2 = '/<br>\n?/is';
>    $result = null;
>
>    while ($string) {
>        $armatch = preg_match($re1, $string, $arMatch);
>        if (is_array($arMatch)) {
>            $result .= $arMatch[1];
>            $result .= preg_replace($re2, "\n", $arMatch[2]);
>            $string = $arMatch[3];
>        }
>        else break;
>    }
>    $result .= $string;
>    return $result;
>}
>
>This assumes that all <pre> are properly closed with </pre>. As said, I
>didn't test, but it should work this or a similar way.
>
>
>-- 
>   >O Ernest E. Vogelsinger 
>   (\) ICQ #13394035 
>    ^ http://www.vogelsinger.at/
>


-- 
Gustaf Sjoberg <[EMAIL PROTECTED]>
 <(" <) <(" )> <( ")> (> ")> 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to