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 Quote Link to comment https://forums.phpfreaks.com/topic/305132-need-help-on-copying-text/ Share on other sites More sharing options...
steveo314 Posted September 29, 2017 Share Posted September 29, 2017 (edited) 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 September 29, 2017 by steveo314 Quote Link to comment https://forums.phpfreaks.com/topic/305132-need-help-on-copying-text/#findComment-1552134 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(). Quote Link to comment https://forums.phpfreaks.com/topic/305132-need-help-on-copying-text/#findComment-1552137 Share on other sites More sharing options...
Barand Posted September 29, 2017 Share Posted September 29, 2017 (edited) 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. Edited September 29, 2017 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/305132-need-help-on-copying-text/#findComment-1552138 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. Quote Link to comment https://forums.phpfreaks.com/topic/305132-need-help-on-copying-text/#findComment-1552139 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. Quote Link to comment https://forums.phpfreaks.com/topic/305132-need-help-on-copying-text/#findComment-1552150 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.