> So, thinking about it a little more, I decided what I was looking for was
> a
> regular expression that would allow me to replace any incidences of
> hyphens
> when not contained within tags (i.e., when not contained between "<" and
> ">").
> 
> And this is where things have ground to a halt.

Hi All,

After toying with this for several hours I decided to give up on trying to
work out a way to achieve this via a single regular expression replacement.

My simpler 'solution' now is to pull out all text not contained within tags
using preg_match_all(), and run a str_replace() across these values to
replace any incidences of hyphens, and then another str_replace() to replace
the content with the substring where hyphens were found.

So, something like:

<?
preg_match_all("/(^|>)(.+?)(<|$)/m", $text,$hypharr);
for ($i=0; $i < count($hypharr[0]); $i++){
        
        $rephyph = str_replace("-","-<span style='font-size: 0px;'>
</span>", $hypharr[0][$i]);
        if ($rephyph <> $hypharr[0][$i]){
                $text= str_replace($hypharr[0][$i],$rephyph,$text);
        }
}

?>

This seems to achieve what I'm looking for, ie replacing hyphens when not
contained in HTML tags.

Regards,

Murray

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

Reply via email to