954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Remove a single table row from cURL results with preg_replace(?)

Hi,

I am using cURL to grab the contents of a webpage which contains a table. I am trying to make an array out of the table contents, with the column headings as the array keys. Unfortunately the first row of the table, before the headers, has pagination which is messing it all up. The row in question is as follows:

<tr class="DGListPager" align="center">

		<td colspan="6"><b>Page: </b><span>1</span>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl01&#39;,&#39;&#39;)">2</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl02&#39;,&#39;&#39;)">3</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl03&#39;,&#39;&#39;)">4</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl04&#39;,&#39;&#39;)">5</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl05&#39;,&#39;&#39;)">6</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl06&#39;,&#39;&#39;)">7</a>&nbsp;<a href="javascript:__doPostBack(&#39;ctl00$oCPH1$dgHistory$ctl01$ctl07&#39;,&#39;&#39;)">8</a></td>

	</tr>


I have tried using preg_replace and preg_filter to simply get rid of the extra row, but I haven't had any luck. I am afraid that my regex skill is sub-par. My best attempt is below:

preg_replace('/<tr class="DGListPager" align="center">(.*?)<\/tr>/', '', $output)

If anyone could point me in the right direction here, ti would be a great help. Thanks

lobstar
Newbie Poster
6 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

After searching around some more, I found the solution. The expression needed the s modifier since there are new lines. So, the final preg_replace looked like:

preg_replace('/<tr class="DGListPager"(.*)\/tr>/iUs', '', $output)
lobstar
Newbie Poster
6 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: