0

I have table like this -> http://jsfiddle.net/jurisKaste/FvgeQ/

And I need to get array of all those numbers from id column... im using php code and I have so far this piece of code from here. i must use php only! Get number from a string

how could i modify this regexp to get a bit readable array ? so the complete code look like this

    $data = str_replace(",", ".", $data); // $data is that html code from fiddle!
    preg_match_all("/[+-]?\d+[\d\.Ee+]*/", $data, $matches);
    var_dump($matches);

edit: what about this ?

    $data = str_replace(",", "", $data);
    preg_match_all("/[0-9]{5,6}/",$data,$matches);
    print var_dump($matches);

it works for me...

2

3 Answers 3

2

Try this, it looks for the first td after each <tr then gets the number in between the <td> and </td>

preg_match_all("/\<tr.+?td.+?\>([\d,]+?)\</s",$string,$matches);
print "<pre>"; var_dump($matches); print "</pre>";
Sign up to request clarification or add additional context in comments.

1 Comment

it's data from google spreadsheet structured query, it gives this id with comma... so i cut it out and use this regexp pattern... and it works... in example i have 6 digit id, but it can be 5 digit too... that's why i wrote {5,6} $data = str_replace(",", "", $data); preg_match_all("/[0-9]{5,6}/",$data,$matches); print "<pre>"; var_dump($matches); print "</pre>";
0

try it

$xml=new SimpleXMLElement($data);
foreach($xml->tr as $tr){
    echo $tr->td[0];
}

Comments

0
$data = str_replace(",", "", $data);
preg_match_all("/[0-9]{5,6}/",$data,$matches);
print var_dump($matches);

Comments

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.