You are here: Newbie: Trouble trying to use strpos(target, bigstring) « PHP Programming Language « IT news, forums, messages
Newbie: Trouble trying to use strpos(target, bigstring)

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация