php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77386 The result is different than it should be.
Submitted: 2018-12-31 10:32 UTC Modified: 2018-12-31 11:16 UTC
From: maikcrew at centrum dot cz Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 7.2.13 OS: Debian
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: maikcrew at centrum dot cz
New email:
PHP Version: OS:

 

 [2018-12-31 10:32 UTC] maikcrew at centrum dot cz
Description:
------------
---
From manual page: https://php.net/function.strpos
---


Test script:
---------------
<?php
  $řetězec = "\"Babylónská rybka,\" odříkával tiše Stopařův průvodce po Galaxii";
  $pozice = strpos($řetězec, "rybka");
  echo "Hledané slovo začíná na pozici $pozice";
?>

Expected result:
----------------
pozice = 12 but php show 14 ? I study book. When I try count position manualy look that is 12.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-31 10:37 UTC] mega6382 at mega6382 dot me
You should use mb_strpos for this http://php.net/manual/en/function.mb-strpos.php

Because your string contains multibyte characters

Example: https://3v4l.org/epioV
 [2018-12-31 10:37 UTC] peehaa@php.net
-Status: Open +Status: Not a bug
 [2018-12-31 10:37 UTC] peehaa@php.net
You are working with strpos which counts bytes. Use mb_strpos
 [2018-12-31 11:16 UTC] maikcrew at centrum dot cz
Thanks for good solution. The book from which I'm learning shows bugs or uncertainties, but when it comes to the PHP.net tutorials, PHP will learn the best.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 05:01:38 2025 UTC