Hello fellas,
I have a form field for URL.
How can I test if there is a "?" or a "=" contained in the URL string?
thanks in advance for your help!
best regards,
Blueman
Hello fellas,
I have a form field for URL.
How can I test if there is a "?" or a "=" contained in the URL string?
thanks in advance for your help!
best regards,
Blueman
You can use say, [man]strpos/man.
Thanks for the hint, but I really need a little more detailed help :-)
Just read the PHP Manual for strpos().
I'd use stristr() (string in string)
http://www.php.net/stristr
if (stristr($url, '?') || stristr($url, '='))
{
echo "URL contains a query string.";
}
HTH!
Thank You, RICHARD.YORK ...
YOU've been VERY helpful
regards,
Blueman
Originally posted by richard.york
I'd use stristr() (string in string)
http://www.php.net/stristr
if (stristr($url, '?') || stristr($url, '='))
{
echo "URL contains a query string.";
}
HTH!
I'd go with Laser's approach.
Originally posted by onion2k
1. strstr is faster, stristr is the case insensitive version.
2. strpos is even faster still if you're just checking whether something is in there.
I'd go with Laser's approach.
strpos it is not very intuitive as to code that explains itself, IMO, and as far as srtstr vs stristr we'd be haggling over fractions of milliseconds anyway. For the majority of low-traffic websites such a thing is inconsequental and a little pedantic-ish.
strpos suggests to me that I want to know where a string occurs inside of a string and I don't really see the argument for it being faster, in fact I'd think it a little slower since it has to count where in the string the string occurs instead of just telling if it is in the string which is a simple boolean operation.
Here's a test. Seems strpos() and strstr() are very close. Really, the main thing that is different between them is their return value (false). And even that will be the same if the needle is not found in the haystack.
However, stristr takes 3 to 4 times as long to complete. If you don't need to do a case insensitive match, then even if the time is in milliseconds, and "inconsequential," a good programmer will still use the faster function. Always make your code as scalable as feasible. I think it's fairly feasible to omit an "i" from your function, don't you? Especially if you are searching for a symbol like ? and =.
My server is hosted, which means there are other sites on the same server. To truly test this purely, it should be done on a server with no load on it. If you want to do so, here is the code.