stig1 Posted March 3, 2009 Share Posted March 3, 2009 Simple question, probably even more simple answer. How can you check a string that is returned from a database that if it has more than 1 space between words, that it will then remove the extra spaces. For example... Made from quality thermal paper treated on one side to produce an image from heat. Should be.. Made from quality thermal paper treated on one side to produce an image from heat. Thanks in advance for your help. Link to comment https://forums.phpfreaks.com/topic/147697-simple-question/ Share on other sites More sharing options...
genericnumber1 Posted March 3, 2009 Share Posted March 3, 2009 The simplest way: <?php $testString = 'Made from quality thermal paper treated on one side to produce an image from heat.'; echo preg_replace('/ +/', ' ', $testString); ?> If you don't mind it removing line breaks you can do \s instead of the space inside of the regex pattern (It's certainly more readable). Link to comment https://forums.phpfreaks.com/topic/147697-simple-question/#findComment-775279 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.