skend0 Posted September 27, 2017 Share Posted September 27, 2017 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 Link to comment Share on other sites More sharing options...
steveo314 Posted September 29, 2017 Share Posted September 29, 2017 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. Link to comment Share on other sites More sharing options...
benanamen Posted September 29, 2017 Share Posted September 29, 2017 Die and Exit are the same. The manual die — Equivalent to exitThis language construct is equivalent to exit(). Link to comment Share on other sites More sharing options...
Barand Posted September 29, 2017 Share Posted September 29, 2017 If you look up die in the manual it will tell you it is functionally equivalent to exit(). Both can output a message so a preceding echo is unnecessary. Link to comment Share on other sites More sharing options...
Psycho Posted September 29, 2017 Share Posted September 29, 2017 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. Link to comment Share on other sites More sharing options...
steveo314 Posted September 29, 2017 Share Posted September 29, 2017 Please delete my reply since I am a dumb twat. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.