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/03/31 13:30]
jeff
uphp:functions:explode [2021/09/13 05:57] (current)
Line 3: Line 3:
 <badge>WMPRO, WMMINI FW >= 1.0</badge> <badge>WMMEGA FW >= 2.0</badge> <badge>WMPRO, WMMINI FW >= 1.0</badge> <badge>WMMEGA FW >= 2.0</badge>
  
-Turn a string into an array+<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></html>
  
 ====Description==== ====Description====
  
-<well size="sm"><html><span style="font-size:125%;color:green">array +<well size="sm"><html> 
-<span style="color:black"></html>[[explode]] +<span style="font-size:125%;color:green">array 
-<html>(+<span style="color:black">explode (
 <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 16: Line 16:
 <span style="color:black">) <span style="color:black">)
 </html></well> </html></well>
-Turn a string into an array by separating out the elements as bounded by a delimiter character+<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>
  
 ====Parameters==== ====Parameters====
  
-<html><span style="color:blue"><b>$value</b><span style="color:black"></html>:  String to be separated into elements in the array+<html><b><span style="color:blue">$value<span style="color:black"></b>:  <b><span style="color:green">String<span style="color:black"></b> to be separated into elements in the <b><span style="color:green">array<span style="color:black"></b></html>
  
-<html><span style="color:blue"><b>$delimiter</b><span style="color:black"></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====
  
-Array of elements+<html><b><span style="color:green">Array<span style="color:black"></b></html> of elements
  
 ====Example==== ====Example====
Line 46: 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>
  
 ====See Also==== ====See Also====
  
-[[implode()]] - Turn an array into a string+[[implode()]] - <html>Turn an <b><span style="color:green">array<span style="color:black"></b> into a <b><span style="color:green">string<span style="color:black"></b></html>
  
-[[print_r()]] - Dump the contents of an array to the current output+[[print_r()]] - Dump the contents of an <html><b><span style="color:green">array<span style="color:black"></b></html> to the current output
  
-[[sizeof()]] - Return the number of elements in an array+[[sizeof()]] - Return the number of elements in an <html><b><span style="color:green">array<span style="color:black"></b></html>
  
 [[uphp:variables|uPHP Variable Types and Limits]] [[uphp:variables|uPHP Variable Types and Limits]]
Line 60: Line 76:
 ====Additional Information==== ====Additional Information====
  
-Note that there is an important difference in the parameter order between mainline PHP and Wattmon uPHP. In the mainline PHP function the delimiter comes first, but in uPHP the string to be exploded comes first:+Note that there is an important difference in the parameter order between mainline PHP and Wattmon uPHP. In the mainline PHP function the delimiter comes first, but in uPHP the <html><b><span style="color:green">string<span style="color:black"></b></html> to be exploded comes first:
  
 <badge>PHP</badge> ''explode(delimiter,string)'' <badge>PHP</badge> ''explode(delimiter,string)''
uphp/functions/explode.1490967018.txt.gz · Last modified: 2021/09/13 05:56 (external edit)