You are here: stripos kills my script but strpos is fine? « PHP « IT news, forums, messages
stripos kills my script but strpos is fine?

Posted by Michael on 02/02/05 17:34

I'm trying to use stripos as a faster and less resource-intensive
alternative to preg_match with the i flag, but I'm getting some strange
behavior.

Here's a test script that demonstrates the problem:
---
<?php
$days = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun");
foreach ($days as $d) {
echo "Checking day: $d";
if (stripos($d, 'T') === 0) {
echo "Day is Tuesday or Thursday";
} else {
echo "Day is MWFSS";
}
}
?>
---
When I run this as-is, it prints "Checking day: Mon" and stops. When I
change stripos to strpos, it runs all the way through doing what it's
supposed to. It's as if stripos calls 'die' somehow and strpos doesn't.

AFAIK, stripos should behave exactly like strpos except
case-insensitively. So in the function above, it should make absolutely
no difference which one I use.

Any thoughts?

Thanks!

PS: Ignore the fact I'm using days above, what I'm really doing has
nothing to do with date handling. That was just a convenient example to
demonstrate the problem.

 

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

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