string explode function - returns an array of strings by splitting the given string
string-implode-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 implode function - returns formated string on the fly from an array</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 implode function - returns formated string on the fly from an array">
<meta name="keywords" content="php, example, code, array, function, implode, string">
<meta name="description" content="string implode function - returns formated string on the fly from an array">
<style>
h2, h4{background:#ccc; color:#000073;}
h2{ padding:3px; margin:3px; font-size:20px;}
h4{ padding:2px; margin:2px; font-size:17px;}
h1{ padding:4px; margin:5px; font-size:23px; background:#FF0000; color:#FFFFFF;}
p{padding:2px; margin:2px; color:#003386;}
body{ background:#FFFFFa;}
</style>
</head>
<body>
<h2>string implode function - returns formated string on the fly from an array</h2>
<pre>
<?php
/*
-----------------------------------------------------------
let's make a string holding comma seperated ages of people
-----------------------------------------------------------
*/
$ageString = "10,20,30,40,50";
echo "<h4>Output of ageString of the people</h4>";
print "<p>$"."ageString = {$ageString}</p>";
/*
--------------------------------------------------------------------------------
we can get 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);
/*
--------------------------------------------------------------------------------
now we want to make the array | separated string on the fly by using
string implode function
--------------------------------------------------------------------------------
*/
$separator = "|";
$finalString = implode($separator, $ageArray);
print "<p>$"."separator = {$separator}</p>";
echo "<h4>Output of finalString by using string implode function</h4>";
print "<h1>$"."finalString = {$finalString}</h1>";
/*
--------------------------------------------------------------------------------
in the professional world this function is also very useful to handel array
to make formated string on the fly.
--------------------------------------------------------------------------------
*/
?>
</pre>
</body>
</html>

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