Link to home
Start Free TrialLog in
Avatar of jccyber
jccyber

asked on

PHP Sracper

Hello Experts,

I am trying to scrape the content of a page and replacing some of the content by my own content! I am also trying to keep the look and feel of the page intact.

 I have added 2 tags to separate the bottom from the top
<!--top-end-->
<!--bottom-start-->

How!!!
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

What part do you want to replace ? between those two ? preg_replace would be the way to go.
Avatar of jccyber
jccyber

ASKER

Whatever is in between
 <!--top-end-->
<!--bottom-start-->
Try this:

<?php
$somehtml = "<html><head></head><body><!--top-end-->some text<!--bottom-start--></body></html>";

$somehtml = preg_replace("/<!--top-end-->(.*?)<!--bottom-start-->/ims", "mytext", $somehtml);

echo $somehtml;

?>
Avatar of jccyber

ASKER

I am currently using this code to get the page


$url="http://mydomain/page.html";
 
$ch = curl_init();
 
curl_setopt($ch, CURLOPT_URL, $url);
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
 
$file=curl_exec ($ch) or die(curl_error());
 
curl_close ($ch);
 


echo $file;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Lukasz Chmielewski
Lukasz Chmielewski
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you want to post the actual URL of the page you want to scrape, we might be able to provide more concrete answers.  But that said, please be sure that you have permission to access the page in an automated manner and that you have copyright for the information you are using.  Many sites do not allow web scraping and explicitly deny this use case in their terms of service.  Also, many sites that want to allow automated access to the underlying data model will offer an API.  Just a thought, ~Ray
Avatar of jccyber

ASKER

This is it.



Thank you