FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » reduce all spaces to one
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: reduce all spaces to one [message #176924 is a reply to message #176923] Sun, 05 February 2012 21:12 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 2/5/2012 3:47 PM, Michael Fesser wrote:
> .oO(Jerry Stuckle)
>
>> On 2/4/2012 9:41 AM, Thomas 'PointedEars' Lahn wrote:
>>>
>>> Note that the newline, which is white-space too, is preserved here.
>>>
>>
>> Newline is preserved in my version also, if you understood ANYTHING
>> about how PHP's regex's work (but we already know you don't).
>
> You want to read the manual and not start a flame war everytime you
> answer to a person you don't like.
>
> By default \s also matches LF and CR, because internally the C library
> function isspace() function is used:
>
> http://www.cplusplus.com/reference/clibrary/cctype/isspace/
>
>> It also
>> takes out tabs - which may be inserted automatically by some editors,
>> for instance, and can be desirable.
>
> Correct, but the OP didn't ask for that.
>
>>> If you want to make the space character in the expression better visible,
>>> you can use
>>>
>>> (1) echo preg_replace('/\ +/', ' ', "here are some \n spaces ");
>>>
>>
>> The search pattern is invalid.
>
> No. You can escape every char you want, even if it's not necessary.
>
>>> or
>>>
>>> (2) echo preg_replace('/\\ +/', ' ', "here are some \n spaces ");
>>>
>>
>> Searches for the sequence '\ '
>
> No. The double backslash is handled by PHP (see escaping in single-
> quoted strings), after then it's just like (1).
>
> BTW: If you want to match a backslash, you'd have to write '\\\\' in the
> pattern.
>
>>> or
>>>
>>> (3) echo preg_replace('/\x20+/', ' ', "here are some \n spaces ");
>>>
>>
>> Ugh!
>
> Perfectly legal and sometimes the only way to define very special
> characters.
>
>>> or
>>>
>>> (4) echo preg_replace('/\\x20+/', ' ', "here are some \n spaces ");
>>>
>>
>> Again, invalid escape sequence.
>
> Again you're wrong, see (2).
>
>> Showing your ignorance again. You do better when you keep your mouth shut.
>
> It's _you_ who should keep the mouth shut in cases like this, especially
> if obviously you didn't take the time to test the given examples, but
> call them invalid instead. But since they just use different escaping
> mechanisms in PHP and the PCRE engine, they're absolutely valid and
> useful in different cases.
>
> Micha
>

That's all we need - another troll in this newsgroup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Stats comp.lang.php (last 7 days)
Next Topic: Check email
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Sep 20 14:48:36 GMT 2024

Total time taken to generate the page: 0.04260 seconds