nesiak Posted May 23, 2007 Share Posted May 23, 2007 I've made this function to replace spaces with "-" and it doesn't work what did i do wrong? <?php $string = "Go for it now"; echo $string; function change($str) { while ($a!=strlen($str)); { $ss =fgetc($file); if ($ss==" ") { $ss = "-"; } $ok = $ok+$ss; $a++; echo $ok; echo $a; } } change($string); ?> Link to comment https://forums.phpfreaks.com/topic/52692-solved-replacing-spaces/ Share on other sites More sharing options...
chigley Posted May 23, 2007 Share Posted May 23, 2007 Instead of all that; why not use this? <?php $string = "Go for it now"; $string = str_replace(" ", "-", $string); echo $string; // Go-for-it-now ?> Link to comment https://forums.phpfreaks.com/topic/52692-solved-replacing-spaces/#findComment-260158 Share on other sites More sharing options...
Corona4456 Posted May 23, 2007 Share Posted May 23, 2007 D'oh chigley beat me to it! Link to comment https://forums.phpfreaks.com/topic/52692-solved-replacing-spaces/#findComment-260160 Share on other sites More sharing options...
nesiak Posted May 23, 2007 Author Share Posted May 23, 2007 Hahaha, thanks ! Link to comment https://forums.phpfreaks.com/topic/52692-solved-replacing-spaces/#findComment-260162 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.