php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50702 strrpos offset argument doesn't work
Submitted: 2010-01-08 22:41 UTC Modified: 2010-01-09 09:47 UTC
From: samuel dot roze at gmail dot com Assigned:
Status: Not a bug Package: Unicode Engine related
PHP Version: 5.3.1 OS: Debian 5
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: samuel dot roze at gmail dot com
New email:
PHP Version: OS:

 

 [2010-01-08 22:41 UTC] samuel dot roze at gmail dot com
Description:
------------
The third sttrpos argument, $offset, doesn't act on data. With are without it, it is the same result.

Reproduce code:
---------------
<?php
$file_path = '/home/mon/fichier/LC_MESSAGES/message.po';
var_dump($file_path);

$last_bracket = strrpos($file_path, '/');
var_dump($last_bracket);

$last_bracket2 = strripos($file_path, '/', 20);
var_dump($last_bracket2);

?>

Expected result:
----------------
string(40) "/home/mon/fichier/LC_MESSAGES/message.po"
int(29)
int(17)

Actual result:
--------------
string(40) "/home/mon/fichier/LC_MESSAGES/message.po"
int(29)
int(29)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-01-09 03:28 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You are searching for the last occurrence starting at position 20, which is still the last. You have to use -20 as offset. Please mind the strrpos documentation:

offset: May be specified to begin searching an arbitrary number of characters into the string. Negative values will stop searching at an arbitrary point prior to the end of the string.
http://php.net/strrpos
 [2010-01-09 09:47 UTC] samuel dot roze at gmail dot com
Oh! I'm really sorry. I thought that $offset was the number of characters that are forgotten at the end of the string.

Thanks!
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 18:01:31 2024 UTC