string join function - joins formated string on the fly from an array

string join function - joins formated string on the fly from an array

string-join-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 join function - joins 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 join function - returns formated string on the fly from an array">
  <meta name="keywords" content="php, example, code, array, function, join, string">
  <meta name="description" content="string join function - returns formated string on the fly from an array">
  <style>
   h2, h4{background:#ddd; color:#000078;}
   h2{ padding:3px; margin:3px; font-size:21px;}
   h4{ padding:2px; margin:2px; font-size:18px;}
   h1{ padding:4px; margin:5px; font-size:22px; background:#FFFF00; color:#000033;}
   p{padding:2px; margin:2px; color:#003376;}
   body{ background:#FFFFFb;}
  </style>
 </head>
 <body>
  <h2>string join function - returns formated string on the fly from an array</h2>
  <pre>
   <?php
    /*
     -----------------------------------------------------------
     let us make a string holding comma seperated ages of people
     -----------------------------------------------------------
    */
    $ageString = "10,20,30,40,50,70";
    echo "<h4>Output of ageString of the people separated by comma</h4>";
    print "<p>$"."ageString = {$ageString}</p>";
    /*
     --------------------------------------------------------------------------------
     we want to 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 in php</h4>";
    print_r($ageArray);
    /*
     --------------------------------------------------------------------------------
     now we want to make the array # separated string on the fly by using 
     string join function
     --------------------------------------------------------------------------------
    */
    $separator = "#";
    $hashSeparatedString = join($separator, $ageArray);
    print "<p>$"."separator = {$separator}</p>";
    echo "<h4>Output of hashSeparatedString by using string join function</h4>";
    print "<h1>$"."hashSeparatedString = {$hashSeparatedString}</h1>";
   ?>
  </pre>
 </body>
</html>

string join function - joins formated string on the fly from an array - output in the browser

No comments:

Post a Comment

leave your comments here..