Re: Regex help needed...

From: Date: Mon, 12 Feb 2001 20:30:49 +0000
Subject: Re: Regex help needed...
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-39260@lists.php.net to get a copy of this message
> This is very close. If the string, " Testing ", had multiple spaces, but > I wanted to convert each space to a "_", then what? I tried: There may be a better way, but here is a lengthy one that works. $checkme = " this is it "; if(ereg("^( )+", $checkme, $match)) { for($i = 0; $i < strlen($match[0]); $i++) { $start .= "_"; } } if(ereg("( )+$", $checkme, $match)) { for($i = 0; $i < strlen($match[0]); $i++) { $end .= "_"; } } $fix = ereg_replace("^( )+", $start, $checkme); $fix = ereg_replace("( )+$", $end, $fix); echo "$fix"; -- Jason Stechschulte jpstech@unoh.edu -- How do Crays and Alphas handle the POSIX problem? -- Larry Wall in <199709050042.RAA29379@wall.org>

« previous php.general (#39260) next »