note 91168 added to function.is-string

From: Date: Thu, 28 May 2009 13:01:16 +0000
Subject: note 91168 added to function.is-string
Groups: php.notes 
Request: Send a blank email to php-notes+get-156106@lists.php.net to get a copy of this message
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 ---- Server IP: 200.185.126.110 Probable Submitter: 189.47.177.174 ---- Manual Page -- http://www.php.net/manual/en/function.is-string.php Edit -- https://master.php.net/note/edit/91168 Del: integrated -- https://master.php.net/note/delete/91168/integrated Del: useless -- https://master.php.net/note/delete/91168/useless Del: bad code -- https://master.php.net/note/delete/91168/bad+code Del: spam -- https://master.php.net/note/delete/91168/spam Del: non-english -- https://master.php.net/note/delete/91168/non-english Del: in docs -- https://master.php.net/note/delete/91168/in+docs Del: other reasons-- https://master.php.net/note/delete/91168 Reject -- https://master.php.net/note/reject/91168 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156106) next »