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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC