Tuesday, 15 May 2012

php using curl and preg_match_all -



php using curl and preg_match_all -

this question has reply here:

php using curl , preg_match_all 1 reply

i sense missing something. using next code pull numbers table. simple looks, cannot seem print. placing code , illustration of table below. please help me find error. want print out numbers in each cell.

//gets site $ch = curl_init(); curl_setopt($ch, curlopt_url, 'http://site.org'); curl_setopt($ch, curlopt_returntransfer, 1); $response = curl_exec($ch); //parse info preg_match_all('/<td align=right>(\d+?)</td>/', $response, $matches2); //prints parsed info print_r($matches2[0]);

here sample of table.

<center><table border=1><tr><th align=left>address</th><th width=50>0</th><th width=50>1</th><th width=50>2</th><th width=50>3</th><th width=50>4</th><th width=50>5</th><th width=50>6</th><th width=50>7</th><th width=50>8</th><th width=50>9</th></tr><tr><td>n7:0</td> <td align=right>1</td> <td align=right>1</td> <td align=right>1</td> <td align=right>99</td> <td align=right>0</td> <td align=right>0</td> <td align=right>0</td> <td align=right>0</td> <td align=right>0</td> <td align=right>0</td> </tr><tr><td>n7:10</td> <td align=right>0</td> <td align=right>7300</td> <td align=right>16400</td> <td align=right>3300</td> <td align=right>2200</td> <td align=right>6100</td> <td align=right>28000</td> <td align=right>18000</td> <td align=right>0</td> <td align=right>0</td> </tr></table></center><hr width=25% align=center>

the php-error-reporting should have given hint. advice set error_reporting e_all , display_errors "on" during development.this have given hint, why don't results:

php warning: preg_match_all(): unknown modifier 't'

so should add together escape slash within regex, because, utilize delimiter.

preg_match_all('/<td align=right>(\d+?)<\/td>/', $response, $matches2);

as always, suggest, using delimiter , maintain regex more readable. take "~". like:

preg_match_all('~<td align=right>(\d+?)</td>~', $response, $matches2);

php curl preg-match-all

No comments:

Post a Comment