Jump to content

[SOLVED] need help on preg_replace


Recommended Posts




i need help, i have a code that will scrap info from another website

and there is a part that i need to replace all


tags with

<div style="border-top:dotted 1px #cccccc; padding-bottom:10px"></div>


my problem is, all tags with HR are being replaced including HR or HRef


<div style="border-top:dotted 1px #cccccc; padding-bottom:10px"></div>ef=domain.com


below is my code

$url = "http://career.capitaland.com";
$ch = curl_init($url);    // initialize curl handle
//curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
//curl_setopt($ch, CURLOPT_FAILONERROR, 1);              // Fail on errors
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);    // allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_PORT, 80);            //Set the port number
curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
curl_setopt($ch, CURLOPT_HEADER, false);

$document = curl_exec($ch);

// $originalString = '<hr>';
      $pattern = '<hr>';
      $replacement = 'div style="border-top:dotted 1px #cccccc; padding-bottom:10px"></div';
      echo preg_replace($pattern, $replacement, $document);

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">


<table width="100%"  border="0" cellspacing="0" cellpadding="0">
<? echo $document; 




hope you could help me with this.



Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

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

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.