note 109139 deleted from function.explode by googleguy

From: Date: Thu, 22 Nov 2012 16:49:16 +0000
Subject: note 109139 deleted from function.explode by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192087@lists.php.net to get a copy of this message
Note Submitter: david at saturnprods dot com ---- <?php function blowup($delimiter,$string){ if(strpos($string,$delimiter)===false){ return array($string); } else{ return explode($delimiter, $string); } } ?> returns you an array always. if it doesn't find the delimiter it simply returns the string but as an array. example: <?php echo blowup('@','cat@dog@mouse'); ?> returns: Array('cat','dog','mouse'); example: <?php echo blowup('@','cat'); ?> returns: Array('hello'); Useful if you have to have at least ONE option [EDIT BY danbrown AT php DOT net: DISCLAIMER - As you may have determined by now, the author meant that the second example will return Array('cat'). The function does not teach felines how to greet the user in the English language.]

« previous php.notes (#192087) next »