string explode function - returns an array of strings by splitting the given string
string-explode-function-example-in-php.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>string explode function - returns an array of strings by splitting the given string</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Author" content="Md Iqbal Hosan">
<meta name="title" content="string explode function - returns an array of strings by splitting the given string">
<meta name="keywords" content="php, example, code, array, function, explode">
<meta name="description" content="string explode function - returns an array of strings by splitting the given string">
<style>
h2, h4{background:#ddd; color:#000078;}
h2{ padding:3px; margin:3px; font-size:21px;}
h4{ padding:2px; margin:2px; font-size:18px;}
p{padding:2px; margin:2px; color:#003376;}
body{ background:#FFFFFb;}
</style>
</head>
<body>
<h2>string explode function - returns an array of strings by splitting the given string</h2>
<pre>
<?php
/*
--------------------------------------------------
let us make a string holding comma separated ages
--------------------------------------------------
*/
$ageString = "10,20,30,40,50";
echo "<h4>Output of ageString</h4>";
print "<p>$"."ageString = {$ageString}</p>";
/*
--------------------------------------------------------------------------------
now we want an array of ages by splitting the string by using explode function
--------------------------------------------------------------------------------
*/
$separator = ",";
$ageArray = explode($separator, $ageString);
print "<p>$"."separator = {$separator}</p>";
echo "<h4>Output of ageArray by using string explode function</h4>";
print_r($ageArray);
/*
--------------------------------------------------------------------------------
in the professional world this function is very useful to handel comma separated
values, comma separated IDS to convert to array on the fly.
--------------------------------------------------------------------------------
*/
?>
</pre>
</body>
</html>

No comments:
Post a Comment
leave your comments here..