RE: [PHP] strncmp function (Forgot code snippit)

From: Date: Thu, 31 Mar 2005 00:52:37 +0000
Subject: RE: [PHP] strncmp function (Forgot code snippit)
Groups: php.general 
Request: Send a blank email to php-general+get-211929@lists.php.net to get a copy of this message
Russ <mailto:russbucket@centurytel.net> on Wednesday, March 30, 2005 1:18 PM said: > I'm new to php and linux. I am trying to replace a password program I > used under windows with a mysql based login. I want to compare the > first character of the first and last name of the user for a capital > letter. Why? What does that accomplish? > <?php > $fname=John; > $lname=Smith; Where's the quotes? > if(strncmp(S,${lname},1) ===0) { > ?> > <h1>strncmp() must have returned returned non-false</h1> non-false = true > <?php > } else { >> > <h3>Strncmp() must have returned false</h3> > <?php > } > ?> Rewrite: <?php $fname = "John"; $lname = "Smith"; if(preg_match("/[A-Z]/", substr($fname ,0 ,1))) { echo "first letter is uppercase."; } else { echo "first letter is not uppercase"; } ?> There might be a better way than a regex but that's the first thing that came to my mind. HTH, Chris.

« previous php.general (#211929) next »