Link to home
Start Free TrialLog in
Avatar of eaweb
eawebFlag for undefined

asked on

PHP TEXT SPLIT

hi
i have this data "241161 20041022C 1675.27Geernaert-Clemencia, M" in an array which i'am splitting from the first 'C'
with this code.

$splitAfterDDATillC=spliti('C',$splitDDA[1],2);
  echo $splitDDA[1];
  echo "</br>";
  echo $splitAfterDDATillC[0];
  echo"data after DDA till C";
  echo "</br>";
  echo $splitAfterDDATillC[1];

and it works.  
 
here the results:

  241161 20041022C 1675.27Geernaert-Clemencia, M data after DDA
  241161 20041022data after DDA till C
  1675.27Geernaert-Clemencia, M data after DDA after C
 
  but now i'am trying to split the first numeric data 241161 20041022 of $splitDDA[1] and
  display "C 1675.27Geernaert-Clemencia, M"
  how must i do that because i tried $splitAfterDDATillC=split('[digit]',$splitDDA[1]);
  but nothing i didn't succeed.
  please advice with some code.
Avatar of mc1arke
mc1arke

You will have to use php's regular expression split to do that

http://uk.php.net/manual/en/function.preg-split.php

If you dont know any regular expression then put another post and I can give you the code (its one line, easy to build if you have done regular expression before)
Something like this should do the trick:

<?php

# This is your string stored in $splitDDA[1]
$stringOne = "241161 20041022C 1675.27Geernaert-Clemencia, M";
# This says to split the string wherever it finds 1 or more digits followed by 1 or more spaces and another 1 or more digits...
$splitArray = preg_split("/[\d]+[\s]+[\d]+/", $stringOne);
# So then the string you want is in $splitArray[1]
echo "This is the string after the beginning rows of digits: " . $splitArray[1];

?>

Another example to clarify:

$stringOne = "hello32432there234324my234324friend2323523";
$splitArray = preg_split("/[\d]+/", $stringOne);
foreach($splitArray as $item)
{
     echo "$item<br>";
}

Gives you:

hello
there
my
friend

There are a lot of other things you can do with preg (meaning perl regular expressions).  If you look at a tutorial on perl regular expressions you will see all of the other options you can use with php's "preg" function (the syntax of the regular expressions should be the same, but you just need to put them in the preg_split PHP function).

Perl regex tutorial: http://www.perl.com/doc/manual/html/pod/perlre.html
PHP's preg_split manual: http://www.php.net/preg_split
Avatar of eaweb

ASKER

thank you very very much. your help was wonderfull.
but now i have this problem with with this long string of numbers

  sometimes the data comes like this
  [   936    230012.10   936    230012.10     0         0.00]
  and sometimes like this
  [0009360000230012.100009360000230012.100000000000000000.00]
 
  what i always need is the fisrt 6 characters with or without 0 or space like this [000936] or [   936] beacause as you see the positions remain the same for both.
  and i will need the data too after the fisrt 6 charater till the two numebrs after the first point[0000230012.10] or
  [    230012.10] of the string
 
  how can i do that with the same procedure of split or must i do that i another way.
ASKER CERTIFIED SOLUTION
Avatar of Autogard
Autogard

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial