Forum Moderators: coopster

Message Too Old, No Replies

Help removing commas

         

bodycount

12:09 pm on May 22, 2009 (gmt 0)

10+ Year Member



I need to remove the commas from the inputstring, I was going to do it the following way, but then realised what if the lengths change then this way would not work. Is there another way of doing this?.

$inputstring = "3090000019,359587013498574,304000000018,AZLF907003ND,0000000027,08-243,13/05/09";

$INPUT1 = substr($inputstring, 0, 10);
$INPUT2 = substr($inputstring, 11, 15);
$INPUT3 = substr($inputstring, 27, 12);
$INPUT4 = substr($inputstring, 40, 12);
$INPUT5 = substr($inputstring, 53, 10);
$INPUT6 = substr($inputstring, 64, 6);
$INPUT7 = substr($inputstring, 71, 8);

//OUTPUT

3090000019
359587013498574
304000000018
AZLF907003ND
0000000027
08-243
13/05/09

kaidok

12:46 pm on May 22, 2009 (gmt 0)

10+ Year Member



Use split function:

$array_inputs = split( ",", $inputstring );

In each index of the created array you have the substrings you want.

rocknbil

3:39 pm on May 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I need to remove the commas from the inputstring

Remove, or split on, as posted above?

One way to remove is

$inputstring = preg_replace(',','',$inputstring);

ayushchd

8:01 pm on May 23, 2009 (gmt 0)

10+ Year Member



$array = explode(",", $inpustring);
$inputstring = str_replace(",", " ", $inputstring);

The first one would create an array while the second one would simply replace the commas in the string :)