Jump to content

Extracting data from text/string


computer guy

Recommended Posts

Hi everyone,

 

 

Is there a way that I can extract the following

 

etaRadio Ratings Dump – Current at 26/03/09<--The date

DJ Joelstar                          14 12 14 15 18 21 16 20.17<--These eight numbers (seperate) and the DJ name

 

 

From a string like this

etaRadio Ratings Dump – Current at 26/03/09
DJ Joelstar                           14 12 14 15 18 21 16 20.17
DJ Ant                                   0 0 0 0 0 0 0 0.00
DJ Jaxon                               18 16 14 19 21 14 17 21.89
DJ Chuckmeister85          19 21 24 32 24 18 23 29.61
DJ Pat4life                           21 20 24 28 21 18 22 28.33
DJ JessieB                            0 0 0 0 0 0 0 0.00

 

Thank you  :)

Link to comment
Share on other sites

try

<?php
$test = 'etaRadio Ratings Dump – Current at 26/03/09
DJ Joelstar                           14 12 14 15 18 21 16 20.17
DJ Ant                                   0 0 0 0 0 0 0 0.00
DJ Jaxon                               18 16 14 19 21 14 17 21.89
DJ Chuckmeister85          19 21 24 32 24 18 23 29.61
DJ Pat4life                           21 20 24 28 21 18 22 28.33
DJ JessieB                            0 0 0 0 0 0 0 0.00';

preg_match('/Current at\s(\d+\/\d+\/\d+)/',$test,$date);
echo $date[1],"<hr />\n";
preg_match_all('/(.*)\s+(([0-9]+ ){7}[0-9\.]+)/',$test,$numbers);
$dj = $numbers[1];
foreach ($dj as $k => $v) $dj[$k] = trim($v);
$num = $numbers[2];
foreach ($num as $k => $v) $num[$k] = explode(' ',trim($v));
$data = array_combine($dj, $num);
echo '<pre>',print_r ($data),'</pre>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.