String Help


Could some one help me with some code?

I would like to check a trim($string) to make sure that is is not all punctuation and spaces

I do not know how to use REGEX so please do not say use it with out giving an example.



Use regex() :)

If you want examples and information on how to use this… I recommend going to


I dont see where on that page will allow me to make this check happen?

I can not figure out how to make it work for the scenario below. because some punctuation is allowed AS LONG as it has some Letters and numbers


I think regex is the way to go on this one (but for the life of me, I wouldn’t know how it’d look; I know nothin about regex :P). Anywayz, if you really want to avoid regex, you could try something like this:

$myPuncts = array(",", “.”, “/”, “?”, “!”, “@”, “&”); // Etc, you know the drill
$myReplacs = array("", “”, “”, “”, “”, “”, “”); // Make sure you have just as many
$myCheckedString = str_replace($myPuncts, $myReplacs, $myString);
if (strlen($myCheckedString) == 0) {
die(“You can’t just use punctuation!”);

The downside is creating the array so it covers ALL possible non-alphanumeric stuff. Hmmz, isn’t there an ‘is_alphanumeric()’ function in PHP by any chance?