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
Next revision Both sides next revision
uphp:functions:explode [2017/04/04 13:09]
jeff
uphp:functions:explode [2021/02/02 10:14]
admin
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 <html><b><span style="color:green">string<span style="color:black"></b></html> into an <html><b><span style="color:green">array<span style="color:black"></b></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></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 <html><b><span style="color:green">string<span style="color:black"></b></html> into an <html><b><span style="color:green">array<span style="color:black"></b></html> 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><b><span style="color:blue">$value<span style="color:black"></b></html>:  <html><b><span style="color:green">String<span style="color:black"></b></html> to be separated into elements in the <html><b><span style="color:green">array<span style="color:black"></b></html>+<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><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 46: Line 46:
 (string) [3] => four (string) [3] => four
  
 +?></pre>
 </code> </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)
 +  
 +</code> 
  
 ====See Also==== ====See Also====
  
-[[implode()]] - Turn an <html><b><span style="color:green">array<span style="color:black"></b></html> into a <html><b><span style="color:green">string<span style="color:black"></b></html>+[[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 <html><b><span style="color:green">array<span style="color:black"></b></html> 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
uphp/functions/explode.txt · Last modified: 2021/09/13 05:57 (external edit)