pixeltrace Posted August 11, 2008 Share Posted August 11, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/119108-solved-need-help-on-preg_replace/ Share on other sites More sharing options...
JasonLewis Posted August 11, 2008 Share Posted August 11, 2008 Why don't you just use str_replace then? If it is only <hr> then it would be easier. Quote Link to comment https://forums.phpfreaks.com/topic/119108-solved-need-help-on-preg_replace/#findComment-613289 Share on other sites More sharing options...
pixeltrace Posted August 11, 2008 Author Share Posted August 11, 2008 sorry i havent used string_replace before. can you guide me on how to code it? thanks! Quote Link to comment https://forums.phpfreaks.com/topic/119108-solved-need-help-on-preg_replace/#findComment-613295 Share on other sites More sharing options...
pixeltrace Posted August 11, 2008 Author Share Posted August 11, 2008 its ok now thanks! Quote Link to comment https://forums.phpfreaks.com/topic/119108-solved-need-help-on-preg_replace/#findComment-613296 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.