php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51313 str_replace doesn't work properly with non-ascii characters.
Submitted: 2010-03-17 09:46 UTC Modified: 2010-03-17 09:52 UTC
From: ez dot amiryo at gmail dot com Assigned:
Status: Not a bug Package: I18N and L10N related
PHP Version: 5.2.13 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ez dot amiryo at gmail dot com
New email:
PHP Version: OS:

 

 [2010-03-17 09:46 UTC] ez dot amiryo at gmail dot com
Description:
------------
str_replace doesn't work properly with non-ascii(128~) characters in arrays.
I tested below script on cp949 machine.

Test script:
---------------
<?php
echo ConvertPokerCardString( 'QS 4C JC 9D JH 7H AC' );

function ConvertPokerCardString( $str )
{
    return( str_replace( array('D','S','H','C'), array('◆','♠','♥'.'♣'), $str ) );

//  below codes works well.
/*
    $str = str_replace( 'D', '◆', $str );
    $str = str_replace( 'H', '♥', $str );
    $str = str_replace( 'S', '♠', $str );
    $str = str_replace( 'C', '♣', $str );
    return $str;
*/
}
?>

Expected result:
----------------
Q♠ 4♣ J♣ 9◆ J♥ 7♥ A♣

Actual result:
--------------
Q♠ 4 J 9◆ J♥♣ 7♥♣ A

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-17 09:47 UTC] ez dot amiryo at gmail dot com
sorry. this was my fault.
 [2010-03-17 09:52 UTC] aharvey@php.net
-Status: Closed +Status: Bogus
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 11:01:31 2025 UTC