Alternative to explode function (PHP)

When you have a set of string in an array or strings separated by comma (or any other character), you can use these two alternative. I prefer the second one 🙂

1
2
3
4
5
6
7
8
9
10
 
//code with explode
$list = explode(",",$astring);
foreach ($astring as $value) {
  echo $value;
  echo "<br />";
}
 
//code with str_replace
echo str_replace(",", "<br />", $astring);

Leave a Reply

Your email address will not be published. Required fields are marked *