|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #13922 FORMAT() output in MySQL can't use str_replace
Submitted: 2001-11-04 16:13 UTC Modified: 2001-11-04 16:19 UTC
From: ron at imperators dot ca Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 4.0.5 OS: Redhat 7.1
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.
Block user comment
Status: Assign to:
Bug Type:
From: ron at imperators dot ca
New email:
PHP Version: OS:


 [2001-11-04 16:13 UTC] ron at imperators dot ca
TO reproduce the problem:

Run a mysql query with the following:

   SELECT FORMAT((1004763843/1800),0) as TimeIndex

This will yeild 558,202. (Including the comma). 

As output from the sample script shows (see below for script):

   Before str_replace = 558,202

This needs to be converted to type int, but doing a settype to integer will return only 558. So any resourceful (pronounced "lazy") php programmer would suggest using str_replace to remove the comma. This does not work: 

   After str_replace = 558,202

So doing the settype still yeilds this: 

   After settype = 558

Is there a way to have settype deal with commas (depending on the locale of course)? Of course the real solution is to use the MYSQL FLOOR, CEILING and ROUND functions, which I have done, but it was still perplexing as to why str_replace wouldn't work correctly on this string. The database library used here is phpDB. 

$query = "SELECT FORMAT((1004763843/1800),0) as TimeIndex";

echo $query."<br>\n";

            $rs = $db->execute($query);

            $TimeIndex = $rs->fields["TimeIndex"];
            echo "Before str_replace = $TimeIndex <BR>\n";
            echo "After str_replace = $TimeIndex <BR>\n";
            echo "After settype = $TimeIndex <BR>\n";


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-04 16:15 UTC]
$TimeIndex = str_replace(",","",$TimeIndex);

str_replace doesn't modify the string you give it.

 [2001-11-04 16:19 UTC] ron at imperators dot ca
Oops. Not enough coffee. ;) 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 20:01:29 2024 UTC