I need to replace whitespaces with a comma only for the first few occurances. For example:
$data = SIP25071 O 4.4 43 4 ERG 02/28/2008 Mike cisco2000 ptime.baseval header, incorrect chk in.
my desired output is:
--------------------
SIP25071,O,4.4,43,4,ERG,02/28/2008,Mike,cisco2000,ptime.baseval header incorrect chk in.
These data are individual bug statistics. I eventually want to write to the database, hence the need for the delimiter.
I would really appreciate, if somebody can help me out.
/Kris
This is wht i have got so far:
Code: Select all
<?php
$str=SIP25071,O,4.4,43,4,ERG,02/28/2008,Mike,cisco2000,ptime.baseval header incorrect chk in.';
$rpl=preg_replace('@([A-Z0-9]+)( )@','$1,',$str);
echo "$rpl";
?>-------
SIP25071,O,4.4,43,4,ERG,02/28/2008,Mike cisco2000,ptime.baseval header incorrect chk in.
Desired output:
--------------
SIP25071,O,4.4,43,4,ERG,02/28/2008,Mike,cisco2000,ptime.baseval header incorrect chk in.
I am stuck, can somebody please help?