rascle Posted March 22, 2011 Share Posted March 22, 2011 Hi I am using preg_match to look through some data (collected from external source which works fine) and display it. I have the preg_match to work fine using: <?php $rhys = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">.......(external website data which works fine)'; preg_match('/<td width="60%" class="dataRegularUlOff">Price<\/td> <td width="40%" class="dataRegularUlOff">([^<]+)</', $work, $matchesarray); print_r($matchesarray[1]); ?> However as the string $rhys wont be present in the actual test.php file that contains the preg_match it doesnt seem to work. I have the data going to a file called dump.txt which works fine, and I can send that info to the test.php page and echo that, however if I save the data to a variable like: <?php $work = file_get_contents("dump.txt");preg_match('/<td width="60%" class="dataRegularUlOff">Price<\/td> <td width="40%" class="dataRegularUlOff">([^<]+)</', $work, $matchesarray); print_r($matchesarray[1]); ?> It doesnt seem to do anything, and the page appears blank. I have tried variations of using fread to try and get it to work, but no luck. Does any one have any idea why it isnt working? Thanks Rhys Link to comment https://forums.phpfreaks.com/topic/231420-problems-with-preg_match/ Share on other sites More sharing options...
AbraCadaver Posted March 22, 2011 Share Posted March 22, 2011 error_reporting(E_ALL); ini_set('display_errors', '1'); Link to comment https://forums.phpfreaks.com/topic/231420-problems-with-preg_match/#findComment-1190985 Share on other sites More sharing options...
rascle Posted March 22, 2011 Author Share Posted March 22, 2011 Thanks for your reply, I added the code but there is still nothing being displayed?? <?php $work = file_get_contents("dump.txt");preg_match('/<td width="60%" class="dataRegularUlOff">Price<\/td> <td width="40%" class="dataRegularUlOff">([^<]+)</', $work, $matchesarray); print_r($matchesarray[1]); error_reporting(E_ALL); ini_set('display_errors', '1'); ?> Thanks Rhys Link to comment https://forums.phpfreaks.com/topic/231420-problems-with-preg_match/#findComment-1190996 Share on other sites More sharing options...
MrXHellboy Posted March 22, 2011 Share Posted March 22, 2011 I don't have your txt file but try this: <?php preg_match('/<td\s+width="60%"\s+class="dataRegularUlOff">Price<\/td>\s+<td\s+width="40%"\s+class="dataRegularUlOff">(.*?)<\/td>/si', $work, $matchesarray); print_r($matchesarray[0]); ?> Link to comment https://forums.phpfreaks.com/topic/231420-problems-with-preg_match/#findComment-1191000 Share on other sites More sharing options...
AbraCadaver Posted March 22, 2011 Share Posted March 22, 2011 Thanks for your reply, I added the code but there is still nothing being displayed?? <?php $work = file_get_contents("dump.txt");preg_match('/<td width="60%" class="dataRegularUlOff">Price<\/td> <td width="40%" class="dataRegularUlOff">([^<]+)</', $work, $matchesarray); print_r($matchesarray[1]); error_reporting(E_ALL); ini_set('display_errors', '1'); ?> Thanks Rhys Put the error code before your code. Doesn't do any good to turn on error reporting after the errors have already happened. Link to comment https://forums.phpfreaks.com/topic/231420-problems-with-preg_match/#findComment-1191042 Share on other sites More sharing options...
rascle Posted March 23, 2011 Author Share Posted March 23, 2011 Thank you for that, the new error is: Notice: Undefined offset: 1 in /home/b25rasc/public_html/test5.php on line 8 However MrXHellBoy's Code works, so thank you both Thanks Again Rhys Link to comment https://forums.phpfreaks.com/topic/231420-problems-with-preg_match/#findComment-1191181 Share on other sites More sharing options...
rascle Posted March 23, 2011 Author Share Posted March 23, 2011 I am not sure how to find the "Solved button" anymore, but this topic has been solved. Thanks Link to comment https://forums.phpfreaks.com/topic/231420-problems-with-preg_match/#findComment-1191182 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.