On Monday 12 February 2001 21:08, Jesse Swensen wrote:
> >> This should be a quick one, but I can't seem to wrap my brain around
> >> it. All I need to do is replace leading or trailing spaces with
> >> underscores.  If there is spaces in between words, leave them alone.
> but I wanted to convert each space to a "_", then what?  I tried:
>
> $fix = ereg_replace("(^ +)|( +$)", "_", $checkme);
>
> and
>
> $fix = ereg_replace("(^[ ]+)|([ ]+$)", "_", $checkme);

preg_match ('/^(\s*)(.*?)(\s*)$/', $checkme, $matches);
$NewString = str_repeat ('_', strlen ($matches [1])).
        $matches [2] .
        str_repeat ('_', strlen ($matches [3]));

not tested, but should work fine.

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

Those who will not reason, are bigots,
those who cannot, are fools,
and those who dare not, are slaves.

- George Gordon Noel Byron (1788-1824), [Lord Byron]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to