0

I've a scraper script:

foreach($html->find('td.Live') as $e)
echo $e->plaintext . '<br>';

The result will look like this:

name 1 status  <br>

And I really need to turn the result into 2 arrays like:

name_array = (name 1, name 2, name 3, name 4)
status_array = (status, status, status, status)

How can I do that?

1
  • paste complete output here so that we can sort out. Commented Oct 2, 2013 at 7:46

2 Answers 2

2
$name_array = $status_array = array();
foreach ($html->find('td.Live') as $e) {
    $parts = explode(" ", trim($e->plaintext));
    $status_array[] = array_pop($parts);
    $name_array[] = trim(implode(" ", $parts));
}
echo "<pre>Names:\n", print_r($name_array, 1), "\nStatuses:\n", print_r($status_array, 1), "</pre>";
Sign up to request clarification or add additional context in comments.

1 Comment

My output looks like this: vaskemaskine 3 Optaget 0 vaskemaskine 4 Resttid: 1:55 230 vaskemaskine 5 Optaget 0 vaskemaskine 6 Optaget 0 vaskemaskine 7 Fri And i need only 2 arrays with Name = (vaskemaskine x, vaskemaskine x) Status = (restid, fri, optaget) Not anything else
0
$name_array = $status_array = array();
foreach($html->find('td.Live') as $e) {
    $segment= explode(' ',$e->plaintext);
    $status_array[] = $segment[2];
    $name_array[] = str_replace($segment[2],'',$e->plaintext);
}
echo 'Name: ';
print_r($name_array);
echo '<br> Status:';
print_r($status_array);

2 Comments

$status_array are blank?
I had rechecked, it works fine for me. If $status_array don't have value then $name_array also will not return any value from this code. please check the spelling and workflow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.