Re: [DONE] Substr by words
| From: | Richard Lynch | Date: | Mon, 31 Oct 2005 06:27:23 +0000 |
| Subject: | Re: [DONE] Substr by words | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-224864@lists.php.net to get a copy of this message | ||
On Sun, October 30, 2005 6:04 am, Marcus Bointon wrote:
> On 29 Oct 2005, at 20:41, Richard Lynch wrote:
>
>> It was probably replacing *TWO* spaces with one.
>>
>> If so, it should really be in a while loop, because there could be 3
>> or more spaces in a row, and if the goal is only single-spaced
>> words...
>
> I can hardly think of a better application for a regex:
>
> $text = preg_replace('/ */', ' ', $text);
Sure.
Now you wanna go re-write all my code that pre-dates preg_* functions
being added to PHP? :-)
Un-paid? :-) :-) :-)
Cuz I probably still do have a while(ststr(...)) str_replace() loop or
two in there somewhere from PHP3.0rc2 days...
Yes, ereg_* were in then.
But they were kinda slow and I didn't undestand Regex then.
Hell, I barely understand it now, really.
There's a certain point where the Regex expression reaches a level of
complexity that I'm just not willing to accept in my code and call it
"maintainable"
/ */ is fine, of course.
But there's lots of times when I know there must be a one-line regex
to replace 10 lines of code, but I don't WANT to use it because I'll
stumble over that one-line Regex every time I have to change it.
--
Like Music?
http://l-i-e.com/artists.htm