Jump to content

Archived

This topic is now archived and is closed to further replies.

Tandem

Preg match

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.