|
Posted by Robert Maas, see http://tinyurl.com/uh3t on 06/28/05 09:53
Thanks to help from Ken Robinson I got my hello-world PHP working:
http://www.rawbw.com/~rem/HelloPlus/hellos.html#php0
and then I went on to get my one-step-beyond-hello-world PHP working:
http://www.rawbw.com/~rem/HelloPlus/hellos.html#php1
but now I'm having trouble with testing one string within other string.
I really wanted the case-insensitive version, but got this error:
Fatal error: Call to undefined function: stripos()
so I switched to case-sensitive strpos, which is available but doesn't
work as I expected. Here is the relevant code:
<?php $qs = $_SERVER['QUERY_STRING']; ?>
Query string is <?php echo $qs; ?><br />
<?php $ipconst = 'IP'; ?>
Looking for <?php echo $ipconst; ?> in the query string.<br />
<?php if (strpos($ipconst, $qs) === false) {
echo "You didn't mention IP this time.";
} else {
echo "You asked for IP number?";
} ?>
Here are test runs without and with presence of the IP sub-string:
http://www.rawbw.com/~rem/HelloPlus/h2.php?whatever
Query string is whatever
Looking for IP in the query string.
You didn't mention IP this time.
(That's correct. IP not mentionned in 'whatever'.)
http://www.rawbw.com/~rem/HelloPlus/h2.php?whatIPever
Query string is whatIPever
Looking for IP in the query string.
You didn't mention IP this time.
(That's not correct! IP is there plain as day. What is wrong with my code?)
After composing the above, before posting, I added this code:
<?php $res = strpos($ipconst, $qs);
echo "Result of strpos is" . $res;
if ($res === false) {
echo " (i.e. false)";
} else {
echo " (i.e. non-false)";
} ?>
<br />Still looking for <?php echo $ipconst; ?> in the query string.
<br />Query string is still <?php echo $qs; ?>
It always shows:
Result of strpos is (i.e. false)
regardless of whether IP is in $qs or not.
Navigation:
[Reply to this message]
|