Hi, What is wrong with this code? I get a blank page. I am basically trying to replace "," with "<br>" in a string which I don't know how long it is or how many times a "," appears. <? $var="my,name,is,jeet"; $pieces = explode(",", $var); $n="0"; $varn=""; $v= $pieces['$n']; while($v != "") { $varn= $varn . "<br>" . $v; $n++; $v= $pieces['$n']; } echo $varn; ?> Please let me know what is wrong with it. Thank you jeet
Here you go... <? $var="my,name,is,jeet"; $pieces = explode(",", $var); $n=0; $varn=""; $v= $pieces[$n]; while($v != "") { $varn= $varn . "<br>" . $v; $n++; $v= $pieces[$n]; } echo $varn; ?> PHP: ...You were trying to turn $n into a string instead of using it as a number. -Matt
An easer way to do this would be to use str_replace() http://us2.php.net/str_replace <? $var="my,name,is,jeet"; echo str_replace(",","<br>",$var); ?> PHP:
Super ! Both your codes work just fine. I should be careful about those ' signs. Thank you so much for the help. Best wishes. jeet