note 128730 added to function.explode

From: Date: Thu, 13 Jul 2023 10:27:32 +0000
Subject: note 128730 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-220689@lists.php.net to get a copy of this message
This wrapper prevents the returning array to include empty entries: function explode_no_empty( $separator = "", $string = "" ) { $array = explode( $separator, $string ); foreach( $array AS $K => $STR ) if ( empty( $STR ) || is_null( $STR ) ) unset( $array[$K] ); return $array; } $input_str = "1,2,3,,5"; $ret_array = explode_no_empty( ",", $input_str ); // result is [1,2,3,5] ---- Server IP: 45.112.84.4 Probable Submitter: 45.91.159.168 (proxied: 151.45.191.168) ---- Manual Page -- https://php.net/manual/en/function.explode.php Edit -- https://main.php.net/note/edit/128730 Del: integrated -- https://main.php.net/note/delete/128730/integrated Del: useless -- https://main.php.net/note/delete/128730/useless Del: bad code -- https://main.php.net/note/delete/128730/bad+code Del: spam -- https://main.php.net/note/delete/128730/spam Del: non-english -- https://main.php.net/note/delete/128730/non-english Del: in docs -- https://main.php.net/note/delete/128730/in+docs Del: other reasons-- https://main.php.net/note/delete/128730 Reject -- https://main.php.net/note/reject/128730 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#220689) next »