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 Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or 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

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: Thu Mar 28 19:01:29 2024 UTC