[thelist] PHP - strings and integers

Means, Eric D eric.d.means at boeing.com
Mon Apr 8 10:35:00 CDT 2002


> I'm currently trying to test if a year passed as part of a
> query string is a
> numeral or not. I am using urls with slashes instead of a
> query string, and
> breaking it up in php, so it comes originally as a string.

Personally I'd use a regular expression to crack up the string.  You can
break it into its component parts and validate it at the same time.

http://www.webreference.com/programming/php/regexps/

For instance:
ereg("/(\d{4})/(\d{2})/(\d{2})/", $query_string)
would allow you to match a year/month/day query string like
www.myplace.com/articles/2002/04/04/.  I'm more familiar with Perl regexps,
but you should also, in the same step, be able to extract the values from
the expression (using the split() function in place of ereg).

Here's another reference on building the regexp strings:
http://www.phpbuilder.com/columns/dario19990616.php3

Also, a google search for "php regular expressions" turns up plenty of hits
for further reading.



More information about the thelist mailing list