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

Add a Patch

Pull Requests

Add a Pull Request

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