Jump to content

[SOLVED] need help on preg_replace


pixeltrace

Recommended Posts

hi,

 

 

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

<hr>

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

becoming

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

 

below is my code

<?php
$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"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>test</td>
  </tr>
  <tr>
    <td>
<? echo $document; 
exit;
?>
</td>
  </tr>
  <tr>
    <td>test</td>
  </tr>
</table>

</body>
</html>

 

 

hope you could help me with this.

 

thanks!

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.