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
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

Link to comment
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

 

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.