Search code examples
phpstrpos

Strange result strrpos php


i'm retrieving strange result using strrpos

$link = "www.mysite.com/?_vc=1&_pgn=2";
$position = strrpos($link,"&_pgn=");
echo "<br/>".$position;

result is black page.

if i change pattern in strrpos like:

$position = strrpos($link,"&");

it give me value

21

What is the problem? can you help me?


Solution

  • After some casual googling over my morning coffee, it would seem you are still using PHP4.

    In PHP 4, strpos( ) uses an entire string as a needle, whereas strrpos( ) limits the needle to a single character. If you pass strrpos( ) a string of more than one character, it silently uses only the first character.

    In PHP 5, strrpos( ) and strripos( ) now behave identically to strpos( ) , in that they find strings instead of just the first character.

    Hence why your code appears to work for most people, yet not for you. I found this here.