Jump to content

preg_replace Help Reqd


gmcust3

Recommended Posts

 

  Quote

 

<?php

 

ini_set('display_errors',true);//Just in case we get some errors, let us know....

 

// create a new cURL resource

$ch = curl_init();

$fp = fopen (dirname(__FILE__) . '/a.txt', 'w+');//This is the file where we save the information

 

// set URL and other appropriate options

curl_setopt($ch, CURLOPT_URL, "http://www.whitepages.com.au/resSearch.do?subscriberName=smith&givenName=&location=Melbourne+VIC");

curl_setopt($ch, CURLOPT_FILE, $fp);

curl_setopt($ch, CURLOPT_HEADER, 0);

 

$file = fopen("a.txt", "r") or exit("Unable to open file!");

 

while(!feof($file))

  {

$regex="/clearfix\"><h1 class(.*)</h1></div><div class/";

echo preg_replace($regex,"",fgets($file));

  }

 

 

fclose($file);

// close cURL resource, and free up system resources

curl_close($ch);

 

?>

 

 

I am getting the Error as

 

Warning: preg_replace() [function.preg-replace]: Unknown modifier 'h' in /var/www/html/Leads/AUS/22.php on line 23

 

 

Any help why ?

Link to comment
https://forums.phpfreaks.com/topic/223754-preg_replace-help-reqd/
Share on other sites

Your delimiter appears within your pattern. Either change your delimiter, or escape it where it appears in the pattern.

 

$regex="~clearfix\"><h1 class(.*)</h1></div><div class~";
//  OR
$regex="/clearfix\"><h1 class(.*)<\/h1><\/div><div class/";

Tried But No Error, No Result.

 

<?php

ini_set('display_errors',true);//Just in case we get some errors, let us know....

// create a new cURL resource
$ch = curl_init();
$fp = fopen (dirname(__FILE__) . '/a.txt', 'w+');//This is the file where we save the information

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.whitepages.com.au/resSearch.do?subscriberName=smith&givenName=&location=Melbourne+VIC");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

$file = fopen("a.txt", "r") or exit("Unable to open file!");

while(!feof($file))
  {
$regex="/clearfix\"><h1 class(.*)<\/h1><\/div><div class/";   
preg_replace($regex,"",fgets($file));
  }

fclose($file);
// close cURL resource, and free up system resources
curl_close($ch);

?>

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.