So, I want to be able to get a digit, say all the number 5s from 423412534152345124 and change them to 7s or any other number. How do I do this? I know I can add 2 to the 5s but I don't know how to select just the 5s. Thanks
something like this: <?php $a = "423412534152345124"; $b = strtr($a, array("5"=>"7")); echo "$b"; ?> Code (markup):
This sort of works. However I get '0.' and then 'E+64'. I just want this to change the numbers, so 5678 to something like, 5794. Thanks
But say the number 1000111010100000111101010000111001110001010111110000101011110001. It doesn't work.
If i run this: <?php $a = "1000111010100000111101010000111001110001010111110000101011110001"; $b = strtr($a, array("1"=>"7")); echo "$b"; ?> Code (markup): it outputs: 7000777070700000777707070000777007770007070777770000707077770007 Code (markup): so works fine for me
Ok, if i do this: <?php $a = "1000111010100000111101010000111001110001010111110000101011110001"; $b = strtr($a, array("1"=>"0","0"=>"1")); echo "$b"; ?> Code (markup): It outputs: 0111000101011111000010101111000110001110101000001111010100001110 Code (markup): so like I said, it does work.
I'm wondering if you are treating an integer as a string, whereas @malky66 is not. Try Konrad's answer on: http://stackoverflow.com/questions/...ared-hosting-is-running-32-or-64-bit-with-php
I used that I used Konrad's solution and it looks like I'm using 64-bit php. However I need this to be able to run on 64 bit and 32 bit. Does that help?
You still haven't answered @ryan_uk's question. Do you treat your numbers as strings? As you can see, @malky66 uses quotes around his variables.
Try to use the var_dump() function: var_dump( $number ); PHP: You'll see, it's an integer Now you can use single quotes and check again; it'll be a string.
No, you can convert in different ways, e.g.: $string = "$number"; $string = (string) $number; $string = strval($number); PHP: Research it as there are pros and cons to some methods and also additional ones such as sprintf, settype, etc. Or even handle it as a string from the start.