Tandem Posted August 15, 2006 Share Posted August 15, 2006 Could anyone demonstrate to me a preg match that detects if the subject contains only spaces?I can't work it out myself.Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/17638-preg-match/ Share on other sites More sharing options...
effigy Posted August 15, 2006 Share Posted August 15, 2006 [code]<pre><?php $string = ' '; echo 'All spaces? '; echo preg_match('/^\x20+$/', $string) ? 'Yes' : 'No' ; ?></pre>[/code]If you're looking for blank lines, change the + to *, and \x20 to \s. \s is more commonly used to represent any kind of whitespace, not only spaces. Link to comment https://forums.phpfreaks.com/topic/17638-preg-match/#findComment-75191 Share on other sites More sharing options...
Tandem Posted August 15, 2006 Author Share Posted August 15, 2006 Works perfectly, thank you very much. Link to comment https://forums.phpfreaks.com/topic/17638-preg-match/#findComment-75196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.