Jump to content

Recommended Posts

Hi there i tried this wway to copy content from site  but problem is not working as expected.

<?php
class Provider
{
    public $Name;
    public $Url;
    private $_func;
    
    public function __construct($name, $url, $func)
    {
        $this->Name = $name;
        $this->Url = $url;
        $this->_func = Closure::bind($func, $this);
    }

    public function RetrieveUrl()
    {
        $url = call_user_func($this->_func);
        
        return $url;
    }
}

$providers = array();

$providers[] = new Provider("erodvert", "http://redirect.ero-advertising.com/speedclicks/in.php?pid=92999&spaceid=3546546&returnurl=", function () {
    $html = file_get_contents($this->Url);
    
    $regex = "/var\s+s\s+?=\s+?[\'\"](.*)[\'\"]/i";
    preg_match($regex, $html, $matches);

    if ($matches) {
        return "http://redirect.ero-advertising.com".$matches[1];
    }

    return "";
});

$arr = array_map(function ($p) {
    return $p->RetrieveUrl();
}, $providers);

header('Content-type: application/json');
die(json_encode($arr));

I need the script to copy content  lined with red on image, as that content always changes

 

post-205525-0-73080800-1506540501_thumb.png

Link to comment
https://forums.phpfreaks.com/topic/305132-need-help-on-copying-text/
Share on other sites

change your last line to

exit;

'die();' is when you have to force the script/program crash due to an error.

 

Also use an 'echo();' before the 'exit();' if you want to print the array to the page. 

Edited by steveo314

I think this is your issue

 

$providers = array();

$providers[] = new Provider("erodvert", "http://redirect.ero-advertising.com/speedclicks/in.php?pid=92999&spaceid=3546546&returnurl=", function () {

$html = file_get_contents($this->Url);

 

You define an array called $providers. Then you append a provider object as a new element in the $providers array. Lastly, you attempt to define the variable $html as the 'Url' property of $this. What is $this? It has no context outside the object. You would have to reference the last element in the $providers array and get the Url property. Why are you even using an array since it seems you have only one element that will be added? Try this

 

$provider = new Provider("erodvert", "http://redirect.ero-advertising.com/speedclicks/in.php?pid=92999&spaceid=3546546&returnurl=", function () {
$html = file_get_contents($provider->Url);

 

In any case verify the contents of $html before running your regex.

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.