note 91168 deleted from function.is-string by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 May 2009 13:02:12 +0000 |
| Subject: | note 91168 deleted from function.is-string by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156107@lists.php.net to get a copy of this message | ||
Note Submitter: Alan Tavares
----
Precisei de uma função para não permitir somente espaços em uma string.
Pensei que essa função resolveria meu caso mas espaços são considerados strings e
também são diferentes de vazio:
Um simples regex resolve o problema:
<?php
$strings=array(
' ',
' ',
' a',
'a ',
'a'
);
foreach ($strings as $string){
echo !eregi('^ {1,}$',$string) ? 'string' : 'not string' ;
}
?>
O exemplo acima imprime:
not string
not string
string
string
string
Needed a function to not only allow spaces in a string.
I thought this function solve my case but spaces are considered strings and are different from
empty:
A simple regex solve the problem:
<?php
$strings=array(
' ',
' ',
' a',
'a ',
'a'
);
foreach ($strings as $string){
echo !eregi('^ {1,}$',$string) ? 'string' : 'not string' ;
}
?>
The above example prints:
not string
not string
string
string
string