I am pulling names from rows using preg_match_all and for whatever reason underscores kill it. The code I have that works is: preg_match_all("'<tr id=\"row(.*?)<\/tr>'si", $html, $matches); foreach($matches[0] as $match){ $playerRow[] = $match; } Code (markup): The issue is when I change the part that says \"row to \"row_0_0 it breaks as follows. preg_match_all("'<tr id=\"row_0_0_(.*?)<\/tr>'si", $html, $matches); foreach($matches[0] as $match){ $playerRow[] = $match; } Code (markup): Any thoughts would be appreciated. obviously the usage of underscores in this way causes the issue although i'm not sure how to escape them or whatever to read them correctly. Thank you
underscores do not need to be escaped. Look here for more info on what needs and what doesnt need to be escaped: http://www.cheatography.com/davechild/cheat-sheets/regular-expressions/ What error are you getting? Can you post some of the html that you run the expression against?
Thank you for your response and the nice cheat sheet. I didn't think you had to escape underscores but for whatever reason it just will not work with them. Below is a piece of the html that I am scraping from: <tr id="row_0_0_0" class="row"> <td class="cell cellLeft"><div class="pName injurable"><a href="/nfl/player?playerId=326&leagueId=94458" id="ttId0_0">Philip Rivers</a><img src="http://d1h60c43tcq0zx.cloudfront.net/static/images/pixel.gif" alt="" class="keeper tooltip" id="ttId1_0" /><img src="http://d1h60c43tcq0zx.cloudfront.net/static/images/pixel.gif" alt="" class="tooltip latestNews tooltip" id="ttId2_0" /></div></td> <td class="cell"><span class="position">QB</span></td><td class="cell"><span class="proTeam">SD</span></td><td class="cell cellRight">7</td> </tr> <tr id="row_0_0_1" class="rowOdd"> <td class="cell cellLeft"><div class="pName injurable"><a href="/nfl/player?playerId=6641&leagueId=94458" id="ttId7_0">Ben Tate</a><img src="http://d1h60c43tcq0zx.cloudfront.net/static/images/pixel.gif" alt="" class="tooltip latestNews tooltip" id="ttId8_0" /></div></td> <td class="cell"><span class="position">RB</span></td><td class="cell cellLeft"><span class="fp"><span class="tooltip error" id="ttId6_1">0.6↓</span></span></td><td class="cell cellRight"><span class="fp"><span>8.37</span></span></td> </tr> Code (markup): There are other rows that are grabbed after these if i'm not specific down to the row_0_0. Thank you.
Thank you this seems to be the right direction. My next issue is that this brings in all rows ie. row_0_0_0 row_0_0_1 row_0_1_0 I need it to only grab rows that start with row_0_0 and not row_0_1. I have tried modifying what you have given me although i really am not understanding the pre_match_all usage very well and need to read up on it a bit more before starting anything like this again Thank you for all of your help. EDIT: Nevermind everything is fine thank you very much it works. I messed something else up when I was testing.