Re: Catch line indetation

From: Date: Fri, 28 Oct 2016 13:19:07 +0000
Subject: Re: Catch line indetation
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-325783@lists.php.net to get a copy of this message
Sorry for the top post. In the regex you can use ^\s*[*] which will catch any white space characters. On October 28, 2016 8:51:35 AM EDT, Richard <inbound-lists-php@listmail.innovate.net> wrote: > > >> Date: Friday, October 28, 2016 12:09:31 +0100 >> From: Ashley Sheridan <ash@ashleysheridan.co.uk> >> >> On 28 October 2016 12:01:16 BST, Narcis Garcia >> <informatica@actiu.net> wrote: >>> Hello, I have a string (I quote here only) as: >>> >>> ' <table>...</table>' >>> >>> As you can see there are 3 spaces at the beginning, but it could >>> be 0 or >>> 4 or any number of spaces. >>> How can I get a string with only the initial spaces part? >>> >>> ' <table>...</table>' -> ' ' >>> 'hello' -> '' >>> ' hello' -> ' ' >>> >>> Thanks. >> >> Have you tried regular expressions? Something like: >> >> ^( )*[^ ] >> >> The first captured match is the number of spaces, from 0 to any >> amount. Not the space between the brackets and before the closing >> square bracket >> > >You need to take into consideration that "whitespace" can be created >by more than the simple "space" (ascii 32) character. A "[horizontal] >tab" (ascii 9) is common, but also look at the top of php trim >function documentation: > > <http://php.net/manual/en/function.trim.php> > >to see the characters that it handles as "whitespace". While "trim" >does the opposite of what you're after, you could likely use the >ctype_space function to accomplish your need: > > <http://php.net/manual/en/function.ctype-space.php> > >e.g., by iterating through the string until it returns "false". Also, >"strpos" could be useful. > > > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, visit: http://www.php.net/unsub.php -- Sent from my Android device with K-9 Mail. Please excuse my brevity.

« previous php.general (#325783) next »