mjahkoh Posted August 19, 2011 Share Posted August 19, 2011 $title = array('Category :','Location:','Address:','Telephone:','City:','Region:','Description :'); How possible is it search for eg spaces and ":" in the array and replace them with nothing and capitalize elements. Regards, Jackson Quote Link to comment https://forums.phpfreaks.com/topic/245203-search-array-and-replace-in-one-swoop/ Share on other sites More sharing options...
codefossa Posted August 19, 2011 Share Posted August 19, 2011 <?php $title = array( 'Category :', 'LocaTioN:', 'addResS:', 'Telephone:', 'City:', 'RegIo n:', 'Description :' ); foreach ($title as $str) { $str = preg_replace('/\s/', '', $str); // remove spaces $str = preg_replace('/:/', '', $str); // remove colons $str = ucfirst(strtolower($str)); // capitalize first letter of word (ucwords if multiple words but then dont remove spaces) $titles[] = $str; } print_r($titles); ?> Quote Link to comment https://forums.phpfreaks.com/topic/245203-search-array-and-replace-in-one-swoop/#findComment-1259418 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.