proud Posted January 15, 2009 Share Posted January 15, 2009 If I have the names john richard and jack.. I want them to be written in the formula "john","richard","jack" .. what is the easiest solution to use because I have got hundreds of names on which I want to apply on them the formula I mentioned above and the only thing that separates them is spaces e.g. (john richard jack mark etc..) Link to comment https://forums.phpfreaks.com/topic/140878-solved-how-to-add-a-charachter-to-all-names/ Share on other sites More sharing options...
Mark Baker Posted January 15, 2009 Share Posted January 15, 2009 $names = "john richard jack mark"; $nameArray = str_word_count($names,2); $nameList = implode('","',$nameArray); if ($nameList > '') { $nameList = '"'.$nameList.'"'; } Link to comment https://forums.phpfreaks.com/topic/140878-solved-how-to-add-a-charachter-to-all-names/#findComment-737367 Share on other sites More sharing options...
RussellReal Posted January 15, 2009 Share Posted January 15, 2009 even though this is solved, I thought I might add something which could be of use to you later on.. <?php function addQuotes(&$val) { $val = "\"".addslashes($val)."\""; } $array = array("mark","jack","jimmy","susan"); array_walk($array,"addQuotes"); echo implode(",",$array); ?> Link to comment https://forums.phpfreaks.com/topic/140878-solved-how-to-add-a-charachter-to-all-names/#findComment-737507 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.