Jump to content

Problems with preg_match


rascle

Recommended Posts

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

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.