PHP IF with wildcard

3 posts by 2 authors in: Forums > CMS Builder
Last Post: December 23, 2008   (RSS)

Re: [rjbathgate] PHP IF with wildcard

By Dave - December 22, 2008

Hi Rob,

Yes, it's totally different in PHP then in MySQL. There's a list of string functions here: http://ca.php.net/manual/en/ref.strings.php

And much more advanced pattern matching functions called "Regular Expressions" that you can learn about that let you do this kind of thing (google for details).

But to keep it simple for now I'd just use this function: http://www.php.net/stripos

Try this:

<?php if (stripos("abc", $_GET['submitted']) !== false): ?>
Found submitted value in "abc" string.
<?php endif ?>

Basically it looks for the second value in the first value. If it find it it returns the offset (0, 1, 2, etc) or false if no match. Hope that helps, let me know if you need more details.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] PHP IF with wildcard

Hey,

Excellent thanks Dave - I was trying with 'regular expressions' but something with my format must've been wrong as I couldn't get that to work either!

Stripos is perfect for now, so thanks!

Merry Christmas
Rob