Comments on: strrpos does not work in PHP http://perberglund.com/blog/2008/07/27/strrpos-does-not-work-in-php/ Mostly Asian Pop Culture Wed, 23 May 2012 08:06:18 +0000 http://wordpress.org/?v=2.0.5 by: mrdeus http://perberglund.com/blog/2008/07/27/strrpos-does-not-work-in-php/#comment-789 Tue, 29 Jul 2008 18:29:39 +0000 http://perberglund.com/blog/2008/07/27/strrpos-does-not-work-in-php/#comment-789 Yeah, I figured it was something like that. It's just that when I think about strrpos I think "strpos but reversed", and by some extreme fluke all the examples I tried (earlier, when I first used it in my code) didn't have any "h" except in "http". The error only showed itself now, years later, when YesAsia changed the format of their product links. I never saw that note in the documentation. Usually they put several examples to show the differences between PHP versions, like they do for strrpos earlier than PHP 4 and for PHP 4 and greater. This is what I hate about typeless programming. If you send a string where a character is expected, a "typed" language would say "What the heck is this?!", where PHP says "Although this isn't at all what was expected, he <em>probably</em> meant the first character in the string, yeah let's go with that". I have to search all my php code just to see that I haven't used it like this somewhere else. I don't think so, since I normally use it for characters, but better safe than sorry. :) Yeah, I figured it was something like that. It’s just that when I think about strrpos I think “strpos but reversed”, and by some extreme fluke all the examples I tried (earlier, when I first used it in my code) didn’t have any “h” except in “http”. The error only showed itself now, years later, when YesAsia changed the format of their product links.

I never saw that note in the documentation. Usually they put several examples to show the differences between PHP versions, like they do for strrpos earlier than PHP 4 and for PHP 4 and greater.

This is what I hate about typeless programming. If you send a string where a character is expected, a “typed” language would say “What the heck is this?!”, where PHP says “Although this isn’t at all what was expected, he probably meant the first character in the string, yeah let’s go with that”.

I have to search all my php code just to see that I haven’t used it like this somewhere else. I don’t think so, since I normally use it for characters, but better safe than sorry. :)

]]>
by: ric http://perberglund.com/blog/2008/07/27/strrpos-does-not-work-in-php/#comment-785 Mon, 28 Jul 2008 08:59:21 +0000 http://perberglund.com/blog/2008/07/27/strrpos-does-not-work-in-php/#comment-785 funny :) i tested your examples, but they worked good on my development system. ok, i am using the latest php5 on debian sid/unstable (php 5.2.6.something). then i checked the documentation on php.net and i found that note: "The needle may be a string of more than one character as of PHP 5.0.0." so now the behaviour of strrpos on your system makes sense, since it uses only the first character of your needle! funny :)

i tested your examples, but they worked good on my development system. ok, i am using the latest php5 on debian sid/unstable (php 5.2.6.something).

then i checked the documentation on php.net and i found that note:
“The needle may be a string of more than one character as of PHP 5.0.0.”
so now the behaviour of strrpos on your system makes sense, since it uses only the first character of your needle!

]]>