Logo

Programming-Idioms

History of Idiom 110 > diff from v17 to v18

Edit summary for version 18 by :
[PHP] 2 ways -> 2 distinct implementations

Version 17

2016-02-23, 21:00:40

Version 18

2016-02-23, 21:00:41

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
$blank = (empty(trim($s)); // php 5.5 and after
$blank = !trim($s); // php 5.4 or older
Code
$blank = (empty(trim($s));
Comments bubble
Php 5.5 and after.
Doc URL
http://php.net/manual/en/ref.strings.php
Doc URL
http://php.net/manual/en/ref.strings.php