Jump to content

preg_replace Help Reqd


gmcust3

Recommended Posts

 

 

<?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
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/";

Link to comment
Share on other sites

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

?>

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.