User Tools

Site Tools


uphp:functions:explode

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
uphp:functions:explode [2017/04/12 12:54]
jeff
uphp:functions:explode [2021/09/13 05:57] (current)
Line 7: Line 7:
 ====Description==== ====Description====
  
-<well size="sm"> +<well size="sm"><html>
-<html>+
 <span style="font-size:125%;color:green">array <span style="font-size:125%;color:green">array
-<span style="color:black"> +<span style="color:black">explode (
-</html> +
-[[explode]] ( +
-<html>+
 <span style="color:green">string <span style="color:green">string
 <span style="color:blue">$value<span style="color:black">, <span style="color:blue">$value<span style="color:black">,
Line 19: Line 15:
 <span style="color:blue">$delimiter <span style="color:blue">$delimiter
 <span style="color:black">) <span style="color:black">)
-</html> +</html></well>
-</well>+
 <html>Turn a <b><span style="color:green">string<span style="color:black"></b> into an <b><span style="color:green">array<span style="color:black"></b> by separating out the elements as bounded by a delimiter character</html> <html>Turn a <b><span style="color:green">string<span style="color:black"></b> into an <b><span style="color:green">array<span style="color:black"></b> by separating out the elements as bounded by a delimiter character</html>
  
Line 29: Line 24:
 <html><b><span style="color:blue">$delimiter<span style="color:black"></b></html>:  Character to use for separation <html><b><span style="color:blue">$delimiter<span style="color:black"></b></html>:  Character to use for separation
  
-====Return Value====+====Return Values====
  
 <html><b><span style="color:green">Array<span style="color:black"></b></html> of elements <html><b><span style="color:green">Array<span style="color:black"></b></html> of elements
Line 51: Line 46:
 (string) [3] => four (string) [3] => four
  
 +?></pre>
 +</code>
 +
 +Note that if only one element is present (without the separator character) then a value of -1 will be returned.  This differs from the PHP implementation.  
 +
 +<code php>
 +<pre><?
 +  $mylist="one";
 +  $myarray=explode($mylist,",");
 +  
 +  // the fix for a single parameter is to use is_array
 +  if (!is_array($myarray)) {
 +    $myarray=array($mylist);
 +  }
 +  print_r($myarray)
 +?></pre>
 </code> </code>
  
uphp/functions/explode.1492001693.txt.gz · Last modified: 2021/09/13 05:56 (external edit)