lostnucleus Posted February 14, 2009 Share Posted February 14, 2009 for example I want to change below string "ThisIsBestPhpHelpSite" (before) to "This Is Best Php Help Site" (after) How can i do that ?? Thanks In advance Link to comment https://forums.phpfreaks.com/topic/145179-how-to-add-a-space-where-letter-goes-capital-in-a-string/ Share on other sites More sharing options...
btherl Posted February 14, 2009 Share Posted February 14, 2009 This almost gets you there: $str = 'ThisIsBestPhpHelpSite'; print preg_replace('/([A-Z])/', ' $1', $str); You'll have an extra space at the front which you can strip off (eg using trim()). Link to comment https://forums.phpfreaks.com/topic/145179-how-to-add-a-space-where-letter-goes-capital-in-a-string/#findComment-761985 Share on other sites More sharing options...
Daniel0 Posted February 14, 2009 Share Posted February 14, 2009 <?php $string = 'ThisIsBestPhpHelpSite'; $newString = preg_replace('#(?<!^)([A-Z])#', ' $1', $string); This will not give you a leading space. Link to comment https://forums.phpfreaks.com/topic/145179-how-to-add-a-space-where-letter-goes-capital-in-a-string/#findComment-761987 Share on other sites More sharing options...
lostnucleus Posted February 14, 2009 Author Share Posted February 14, 2009 Thanks btherl & Daniel0 for your time and solution. Link to comment https://forums.phpfreaks.com/topic/145179-how-to-add-a-space-where-letter-goes-capital-in-a-string/#findComment-762008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.