Logo

Programming-Idioms

History of Idiom 110 > diff from v15 to v16

Edit summary for version 16 by :
[PHP] conciseness

Version 15

2016-02-23, 13:33:28

Version 16

2016-02-23, 14:32:27

Idiom #110 Check if string is blank

Set boolean blank to true if string s is empty, or null, or contains only whitespace ; false otherwise.

Idiom #110 Check if string is blank

Set boolean blank to true if string s is empty, or null, or contains only whitespace ; false otherwise.

Code
if(empty($s) || is_null($s) || empty(trim($s))) {
  $blank = true;
}
else
{
  $blank = false;
}
Code
$blank = (empty(trim($s)); // php 5.5 and after
$blank = !trim($s); // php 5.4 or older
Doc URL
http://php.net/manual/en/ref.strings.php
Doc URL
http://php.net/manual/en/ref.strings.php