Merging plaintext from multiple pages - javascript

I'd like to merge multiple pages from a game into a single page. For example:
http://politicsandwar.com/api/tradeprice/resource=aluminum
http://politicsandwar.com/api/tradeprice/resource=food
I tried Javascript using $.ajax() and $.getJSON(). I got a "No 'Access-Control-Allow-Origin" error. So I can't use these tools.
I can actually access those sites as plaintext and parse it as JSON later.
But I can't seem to find any way to parse multiple websites into a single file. It seems to be a trivial thing, considering there are so many tools that can scrape complex content within websites. I just need something that can combine it as plaintext!
I'm open to using any language for this.

You can use PHP to load those files.
Use an array to parse the URL's using file_get_contents and concatenate it to a string and the parse.
$urls = array("http://politicsandwar.com/api/tradeprice/resource=aluminum","http://politicsandwar.com/api/tradeprice/resource=food");
$json = array();
for ($i=0; $i < count($urls); $i++) {
// Push the decoded JSON from the URL
array_push($json, json_decode(file_get_contents($urls[$i]) ));
}
// Set the content type to JSON and echoes it
header('Content-Type: application/json');
echo json_encode($json);

Related

How to retrieve content in PHP from external JavaScript

I have an external JavaScript file, I would like to display array content in my PHP page. How can I display the content by loop. I tried to display the content using following code. But Failed.
<?php
ini_set('allow_url_fopen', 'On');
$feed = file_get_contents("https://example.com/media-list.js");
$array = json_decode($json);
var_dump($array);
$urlPoster=array();
foreach ($array as $value) {
$urlPoster[]=$value->urlPoster;
}
print_r($urlPoster);
?>
media-list.js content
var contents = {
"0W7EHsR8":{
"attachmentCode":"0W7EHsR8",
"title":"title1",
},
"vciym7Zb4":{
"attachmentCode":"vciym7Zb4",
"title":"title2",
},
"XlKBM6":{
"attachmentCode":"XlKBM6",
"title":"Title3",
}
};
I would like to display content like
Title is "title1" .
Title is "title2".
You are trying to use json_decode() on a Javascript Array. JSON and Javascript are two different things.
You need to convert your contents array to JSON, save it in a different file (contents.json for example) and load that file with file_get_contents.
If you need to do this only once you can do something like
var contents = {
"0W7EHsR8":{
"attachmentCode":"0W7EHsR8",
"title":"title1",
},
"vciym7Zb4":{
"attachmentCode":"vciym7Zb4",
"title":"title2",
},
"XlKBM6":{
"attachmentCode":"XlKBM6",
"title":"Title3",
}
};
console.log(JSON.stringify(contents));
and copy the result from the console (click CTRL+Shift+I to open it).
JSON.stringify() takes a Javascript array and turns it into a JSON string.
for this small array the JSON equivalent is
{"0W7EHsR8":{"attachmentCode":"0W7EHsR8","title":"title1"},"vciym7Zb4":{"attachmentCode":"vciym7Zb4","title":"title2"},"XlKBM6":{"attachmentCode":"XlKBM6","title":"Title3"}}
If you intend on making this dynamic (say, loading all attachemnts from a database) you can create a php file that loads that data into an array and returns it into proper JSON using json_encode(). Loading that file with file_get_contents and using json_decode like you are doing now should do the trick.

PHP Curl - Possible to retrieve Javascript results?

I've done the research and most people seem to say there is no great way for this, but I'd like to ask again.
A 3rd party site is returning a value I need via Javascript. Meaning when I view the source of the page I see lots of JS but in the browser it shows me a simple string. When I use CURL I just get the raw JS.
The string I need is simply something like 4b71ec1a4cc2a95f9dfa1c023ecd74e6 The JS that generates this is about 50 lines long. Any way PHP can process this for me?
The source including the JS is:
<!doctype html><html><head></head><body><script>var _0x916d=["\x6C\x20\x42\x28\x78\x2C\x6B\x29\x7B\x70\x20\x61\x3D\x78\x5B\x30\x5D\x2C\x62\x3D\x78\x5B\x31\x5D\x2C\x63\x3D\x78\x5B\x32\x5D\x2C\x64\x3D\x78\x5B\x33\x5D\x3B\x61\x3D\x68\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x30\x5D\x2C\x37\x2C\x2D\x31\x77\x29\x3B\x64\x3D\x68\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x5D\x2C\x31\x32\x2C\x2D\x31\x76\x29\x3B\x63\x3D\x68\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x32\x5D\x2C\x31\x37\x2C\x31\x78\x29\x3B\x62\x3D\x68\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x33\x5D\x2C\x32\x32\x2C\x2D\x31\x79\x29\x3B\x61\x3D\x68\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x34\x5D\x2C\x37\x2C\x2D\x31\x7A\x29\x3B\x64\x3D\x68\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x35\x5D\x2C\x31\x32\x2C\x31\x75\x29\x3B\x63\x3D\x68\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x36\x5D\x2C\x31\x37\x2C\x2D\x31\x74\x29\x3B\x62\x3D\x68\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x37\x5D\x2C\x32\x32\x2C\x2D\x31\x6F\x29\x3B\x61\x3D\x68\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x38\x5D\x2C\x37\x2C\x31\x6E\x29\x3B\x64\x3D\x68\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x39\x5D\x2C\x31\x32\x2C\x2D\x31\x70\x29\x3B\x63\x3D\x68\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x30\x5D\x2C\x31\x37\x2C\x2D\x31\x71\x29\x3B\x62\x3D\x68\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x31\x5D\x2C\x32\x32\x2C\x2D\x31\x73\x29\x3B\x61\x3D\x68\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x32\x5D\x2C\x37\x2C\x31\x72\x29\x3B\x64\x3D\x68\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x33\x5D\x2C\x31\x32\x2C\x2D\x31\x41\x29\x3B\x63\x3D\x68\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x34\x5D\x2C\x31\x37\x2C\x2D\x31\x42\x29\x3B\x62\x3D\x68\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x35\x5D\x2C\x32\x32\x2C\x31\x4C\x29\x3B\x61\x3D\x65\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x5D\x2C\x35\x2C\x2D\x31\x4B\x29\x3B\x64\x3D\x65\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x36\x5D\x2C\x39\x2C\x2D\x31\x4D\x29\x3B\x63\x3D\x65\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x31\x5D\x2C\x31\x34\x2C\x31\x4E\x29\x3B\x62\x3D\x65\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x30\x5D\x2C\x32\x30\x2C\x2D\x31\x4F\x29\x3B\x61\x3D\x65\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x35\x5D\x2C\x35\x2C\x2D\x31\x4A\x29\x3B\x64\x3D\x65\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x30\x5D\x2C\x39\x2C\x31\x49\x29\x3B\x63\x3D\x65\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x35\x5D\x2C\x31\x34\x2C\x2D\x31\x6D\x29\x3B\x62\x3D\x65\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x34\x5D\x2C\x32\x30\x2C\x2D\x31\x43\x29\x3B\x61\x3D\x65\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x39\x5D\x2C\x35\x2C\x31\x45\x29\x3B\x64\x3D\x65\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x34\x5D\x2C\x39\x2C\x2D\x31\x46\x29\x3B\x63\x3D\x65\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x33\x5D\x2C\x31\x34\x2C\x2D\x31\x48\x29\x3B\x62\x3D\x65\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x38\x5D\x2C\x32\x30\x2C\x31\x47\x29\x3B\x61\x3D\x65\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x33\x5D\x2C\x35\x2C\x2D\x31\x50\x29\x3B\x64\x3D\x65\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x32\x5D\x2C\x39\x2C\x2D\x31\x69\x29\x3B\x63\x3D\x65\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x37\x5D\x2C\x31\x34\x2C\x51\x29\x3B\x62\x3D\x65\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x32\x5D\x2C\x32\x30\x2C\x2D\x52\x29\x3B\x61\x3D\x67\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x35\x5D\x2C\x34\x2C\x2D\x55\x29\x3B\x64\x3D\x67\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x38\x5D\x2C\x31\x31\x2C\x2D\x53\x29\x3B\x63\x3D\x67\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x31\x5D\x2C\x31\x36\x2C\x54\x29\x3B\x62\x3D\x67\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x34\x5D\x2C\x32\x33\x2C\x2D\x31\x6C\x29\x3B\x61\x3D\x67\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x5D\x2C\x34\x2C\x2D\x31\x67\x29\x3B\x64\x3D\x67\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x34\x5D\x2C\x31\x31\x2C\x31\x66\x29\x3B\x63\x3D\x67\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x37\x5D\x2C\x31\x36\x2C\x2D\x31\x65\x29\x3B\x62\x3D\x67\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x30\x5D\x2C\x32\x33\x2C\x2D\x31\x68\x29\x3B\x61\x3D\x67\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x33\x5D\x2C\x34\x2C\x56\x29\x3B\x64\x3D\x67\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x30\x5D\x2C\x31\x31\x2C\x2D\x31\x6B\x29\x3B\x63\x3D\x67\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x33\x5D\x2C\x31\x36\x2C\x2D\x31\x6A\x29\x3B\x62\x3D\x67\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x36\x5D\x2C\x32\x33\x2C\x31\x64\x29\x3B\x61\x3D\x67\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x39\x5D\x2C\x34\x2C\x2D\x31\x63\x29\x3B\x64\x3D\x67\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x32\x5D\x2C\x31\x31\x2C\x2D\x59\x29\x3B\x63\x3D\x67\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x35\x5D\x2C\x31\x36\x2C\x58\x29\x3B\x62\x3D\x67\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x32\x5D\x2C\x32\x33\x2C\x2D\x57\x29\x3B\x61\x3D\x66\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x30\x5D\x2C\x36\x2C\x2D\x5A\x29\x3B\x64\x3D\x66\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x37\x5D\x2C\x31\x30\x2C\x31\x38\x29\x3B\x63\x3D\x66\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x34\x5D\x2C\x31\x35\x2C\x2D\x31\x62\x29\x3B\x62\x3D\x66\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x35\x5D\x2C\x32\x31\x2C\x2D\x31\x61\x29\x3B\x61\x3D\x66\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x31\x32\x5D\x2C\x36\x2C\x31\x39\x29\x3B\x64\x3D\x66\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x33\x5D\x2C\x31\x30\x2C\x2D\x31\x44\x29\x3B\x63\x3D\x66\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x31\x30\x5D\x2C\x31\x35\x2C\x2D\x31\x52\x29\x3B\x62\x3D\x66\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x5D\x2C\x32\x31\x2C\x2D\x32\x6A\x29\x3B\x61\x3D\x66\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x38\x5D\x2C\x36\x2C\x32\x66\x29\x3B\x64\x3D\x66\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x35\x5D\x2C\x31\x30\x2C\x2D\x32\x69\x29\x3B\x63\x3D\x66\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x36\x5D\x2C\x31\x35\x2C\x2D\x32\x68\x29\x3B\x62\x3D\x66\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x31\x33\x5D\x2C\x32\x31\x2C\x32\x65\x29\x3B\x61\x3D\x66\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x6B\x5B\x34\x5D\x2C\x36\x2C\x2D\x32\x6B\x29\x3B\x64\x3D\x66\x28\x64\x2C\x61\x2C\x62\x2C\x63\x2C\x6B\x5B\x31\x31\x5D\x2C\x31\x30\x2C\x2D\x31\x51\x29\x3B\x63\x3D\x66\x28\x63\x2C\x64\x2C\x61\x2C\x62\x2C\x6B\x5B\x32\x5D\x2C\x31\x35\x2C\x32\x63\x29\x3B\x62\x3D\x66\x28\x62\x2C\x63\x2C\x64\x2C\x61\x2C\x6B\x5B\x39\x5D\x2C\x32\x31\x2C\x2D\x31\x57\x29\x3B\x78\x5B\x30\x5D\x3D\x6F\x28\x61\x2C\x78\x5B\x30\x5D\x29\x3B\x78\x5B\x31\x5D\x3D\x6F\x28\x62\x2C\x78\x5B\x31\x5D\x29\x3B\x78\x5B\x32\x5D\x3D\x6F\x28\x63\x2C\x78\x5B\x32\x5D\x29\x3B\x78\x5B\x33\x5D\x3D\x6F\x28\x64\x2C\x78\x5B\x33\x5D\x29\x7D\x6C\x20\x77\x28\x71\x2C\x61\x2C\x62\x2C\x78\x2C\x73\x2C\x74\x29\x7B\x61\x3D\x6F\x28\x6F\x28\x61\x2C\x71\x29\x2C\x6F\x28\x78\x2C\x74\x29\x29\x3B\x6D\x20\x6F\x28\x28\x61\x3C\x3C\x73\x29\x7C\x28\x61\x3E\x3E\x3E\x28\x31\x58\x2D\x73\x29\x29\x2C\x62\x29\x7D\x6C\x20\x68\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x78\x2C\x73\x2C\x74\x29\x7B\x6D\x20\x77\x28\x28\x62\x26\x63\x29\x7C\x28\x28\x7E\x62\x29\x26\x64\x29\x2C\x61\x2C\x62\x2C\x78\x2C\x73\x2C\x74\x29\x7D\x6C\x20\x65\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x78\x2C\x73\x2C\x74\x29\x7B\x6D\x20\x77\x28\x28\x62\x26\x64\x29\x7C\x28\x63\x26\x28\x7E\x64\x29\x29\x2C\x61\x2C\x62\x2C\x78\x2C\x73\x2C\x74\x29\x7D\x6C\x20\x67\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x78\x2C\x73\x2C\x74\x29\x7B\x6D\x20\x77\x28\x62\x5E\x63\x5E\x64\x2C\x61\x2C\x62\x2C\x78\x2C\x73\x2C\x74\x29\x7D\x6C\x20\x66\x28\x61\x2C\x62\x2C\x63\x2C\x64\x2C\x78\x2C\x73\x2C\x74\x29\x7B\x6D\x20\x77\x28\x63\x5E\x28\x62\x7C\x28\x7E\x64\x29\x29\x2C\x61\x2C\x62\x2C\x78\x2C\x73\x2C\x74\x29\x7D\x6C\x20\x4F\x28\x73\x29\x7B\x31\x56\x3D\x27\x27\x3B\x70\x20\x6E\x3D\x73\x2E\x43\x2C\x76\x3D\x5B\x31\x55\x2C\x2D\x32\x64\x2C\x2D\x31\x53\x2C\x31\x54\x5D\x2C\x69\x3B\x75\x28\x69\x3D\x41\x3B\x69\x3C\x3D\x73\x2E\x43\x3B\x69\x2B\x3D\x41\x29\x7B\x42\x28\x76\x2C\x4E\x28\x73\x2E\x4D\x28\x69\x2D\x41\x2C\x69\x29\x29\x29\x7D\x73\x3D\x73\x2E\x4D\x28\x69\x2D\x41\x29\x3B\x70\x20\x72\x3D\x5B\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x2C\x30\x5D\x3B\x75\x28\x69\x3D\x30\x3B\x69\x3C\x73\x2E\x43\x3B\x69\x2B\x2B\x29\x72\x5B\x69\x3E\x3E\x32\x5D\x7C\x3D\x73\x2E\x7A\x28\x69\x29\x3C\x3C\x28\x28\x69\x25\x34\x29\x3C\x3C\x33\x29\x3B\x72\x5B\x69\x3E\x3E\x32\x5D\x7C\x3D\x31\x59\x3C\x3C\x28\x28\x69\x25\x34\x29\x3C\x3C\x33\x29\x3B\x4B\x28\x69\x3E\x31\x5A\x29\x7B\x42\x28\x76\x2C\x72\x29\x3B\x75\x28\x69\x3D\x30\x3B\x69\x3C\x31\x36\x3B\x69\x2B\x2B\x29\x72\x5B\x69\x5D\x3D\x30\x7D\x72\x5B\x31\x34\x5D\x3D\x6E\x2A\x38\x3B\x42\x28\x76\x2C\x72\x29\x3B\x6D\x20\x76\x7D\x6C\x20\x4E\x28\x73\x29\x7B\x70\x20\x44\x3D\x5B\x5D\x2C\x69\x3B\x75\x28\x69\x3D\x30\x3B\x69\x3C\x41\x3B\x69\x2B\x3D\x34\x29\x7B\x44\x5B\x69\x3E\x3E\x32\x5D\x3D\x73\x2E\x7A\x28\x69\x29\x2B\x28\x73\x2E\x7A\x28\x69\x2B\x31\x29\x3C\x3C\x38\x29\x2B\x28\x73\x2E\x7A\x28\x69\x2B\x32\x29\x3C\x3C\x31\x36\x29\x2B\x28\x73\x2E\x7A\x28\x69\x2B\x33\x29\x3C\x3C\x32\x34\x29\x7D\x6D\x20\x44\x7D\x70\x20\x45\x3D\x27\x32\x61\x27\x2E\x32\x62\x28\x27\x27\x29\x3B\x6C\x20\x4A\x28\x6E\x29\x7B\x70\x20\x73\x3D\x27\x27\x2C\x6A\x3D\x30\x3B\x75\x28\x3B\x6A\x3C\x34\x3B\x6A\x2B\x2B\x29\x73\x2B\x3D\x45\x5B\x28\x6E\x3E\x3E\x28\x6A\x2A\x38\x2B\x34\x29\x29\x26\x49\x5D\x2B\x45\x5B\x28\x6E\x3E\x3E\x28\x6A\x2A\x38\x29\x29\x26\x49\x5D\x3B\x6D\x20\x73\x7D\x6C\x20\x4C\x28\x78\x29\x7B\x75\x28\x70\x20\x69\x3D\x30\x3B\x69\x3C\x78\x2E\x43\x3B\x69\x2B\x2B\x29\x78\x5B\x69\x5D\x3D\x4A\x28\x78\x5B\x69\x5D\x29\x3B\x6D\x20\x78\x2E\x32\x39\x28\x27\x27\x29\x7D\x6C\x20\x48\x28\x73\x29\x7B\x6D\x20\x4C\x28\x4F\x28\x73\x29\x29\x7D\x6C\x20\x6F\x28\x61\x2C\x62\x29\x7B\x6D\x28\x61\x2B\x62\x29\x26\x32\x38\x7D\x4B\x28\x48\x28\x27\x32\x35\x27\x29\x21\x3D\x27\x32\x36\x27\x29\x7B\x6C\x20\x6F\x28\x78\x2C\x79\x29\x7B\x70\x20\x47\x3D\x28\x78\x26\x46\x29\x2B\x28\x79\x26\x46\x29\x2C\x50\x3D\x28\x78\x3E\x3E\x31\x36\x29\x2B\x28\x79\x3E\x3E\x31\x36\x29\x2B\x28\x47\x3E\x3E\x31\x36\x29\x3B\x6D\x28\x50\x3C\x3C\x31\x36\x29\x7C\x28\x47\x26\x46\x29\x7D\x7D\x6C\x20\x73\x28\x73\x29\x7B\x6D\x20\x48\x28\x22\x32\x37\x22\x2B\x73\x2B\x22\x32\x67\x22\x29\x7D","\x7C","\x73\x70\x6C\x69\x74","\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x67\x67\x7C\x69\x69\x7C\x68\x68\x7C\x66\x66\x7C\x7C\x7C\x7C\x66\x75\x6E\x63\x74\x69\x6F\x6E\x7C\x72\x65\x74\x75\x72\x6E\x7C\x7C\x61\x64\x64\x33\x32\x7C\x76\x61\x72\x7C\x7C\x74\x61\x69\x6C\x7C\x7C\x7C\x66\x6F\x72\x7C\x73\x74\x61\x74\x65\x7C\x63\x6D\x6E\x7C\x7C\x7C\x63\x68\x61\x72\x43\x6F\x64\x65\x41\x74\x7C\x36\x34\x7C\x6D\x64\x35\x63\x79\x63\x6C\x65\x7C\x6C\x65\x6E\x67\x74\x68\x7C\x6D\x64\x35\x62\x6C\x6B\x73\x7C\x68\x65\x78\x5F\x63\x68\x72\x7C\x30\x78\x46\x46\x46\x46\x7C\x6C\x73\x77\x7C\x6D\x64\x35\x7C\x30\x78\x30\x46\x7C\x72\x68\x65\x78\x7C\x69\x66\x7C\x68\x65\x78\x7C\x73\x75\x62\x73\x74\x72\x69\x6E\x67\x7C\x6D\x64\x35\x62\x6C\x6B\x7C\x6D\x64\x35\x31\x7C\x6D\x73\x77\x7C\x31\x37\x33\x35\x33\x32\x38\x34\x37\x33\x7C\x31\x39\x32\x36\x36\x30\x37\x37\x33\x34\x7C\x32\x30\x32\x32\x35\x37\x34\x34\x36\x33\x7C\x31\x38\x33\x39\x30\x33\x30\x35\x36\x32\x7C\x33\x37\x38\x35\x35\x38\x7C\x36\x38\x31\x32\x37\x39\x31\x37\x34\x7C\x39\x39\x35\x33\x33\x38\x36\x35\x31\x7C\x35\x33\x30\x37\x34\x32\x35\x32\x30\x7C\x34\x32\x31\x38\x31\x35\x38\x33\x35\x7C\x31\x39\x38\x36\x33\x30\x38\x34\x34\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x7C\x31\x31\x32\x36\x38\x39\x31\x34\x31\x35\x7C\x31\x37\x30\x30\x34\x38\x35\x35\x37\x31\x7C\x35\x37\x34\x33\x34\x30\x35\x35\x7C\x31\x34\x31\x36\x33\x35\x34\x39\x30\x35\x7C\x36\x34\x30\x33\x36\x34\x34\x38\x37\x7C\x37\x36\x30\x32\x39\x31\x38\x39\x7C\x31\x35\x35\x34\x39\x37\x36\x33\x32\x7C\x31\x32\x37\x32\x38\x39\x33\x33\x35\x33\x7C\x31\x35\x33\x30\x39\x39\x32\x30\x36\x30\x7C\x31\x30\x39\x34\x37\x33\x30\x36\x34\x30\x7C\x35\x31\x34\x30\x33\x37\x38\x34\x7C\x37\x32\x32\x35\x32\x31\x39\x37\x39\x7C\x33\x35\x38\x35\x33\x37\x32\x32\x32\x7C\x33\x35\x33\x30\x39\x35\x35\x36\x7C\x36\x36\x30\x34\x37\x38\x33\x33\x35\x7C\x31\x37\x37\x30\x30\x33\x35\x34\x31\x36\x7C\x34\x35\x37\x30\x35\x39\x38\x33\x7C\x31\x39\x35\x38\x34\x31\x34\x34\x31\x37\x7C\x34\x32\x30\x36\x33\x7C\x31\x38\x30\x34\x36\x30\x33\x36\x38\x32\x7C\x31\x39\x39\x30\x34\x30\x34\x31\x36\x32\x7C\x31\x34\x37\x33\x32\x33\x31\x33\x34\x31\x7C\x31\x32\x30\x30\x30\x38\x30\x34\x32\x36\x7C\x33\x38\x39\x35\x36\x34\x35\x38\x36\x7C\x36\x38\x30\x38\x37\x36\x39\x33\x36\x7C\x36\x30\x36\x31\x30\x35\x38\x31\x39\x7C\x31\x30\x34\x34\x35\x32\x35\x33\x33\x30\x7C\x31\x37\x36\x34\x31\x38\x38\x39\x37\x7C\x34\x30\x33\x34\x31\x31\x30\x31\x7C\x31\x35\x30\x32\x30\x30\x32\x32\x39\x30\x7C\x34\x30\x35\x35\x33\x37\x38\x34\x38\x7C\x31\x38\x39\x34\x39\x38\x36\x36\x30\x36\x7C\x35\x36\x38\x34\x34\x36\x34\x33\x38\x7C\x31\x30\x31\x39\x38\x30\x33\x36\x39\x30\x7C\x31\x31\x36\x33\x35\x33\x31\x35\x30\x31\x7C\x31\x38\x37\x33\x36\x33\x39\x36\x31\x7C\x33\x38\x30\x31\x36\x30\x38\x33\x7C\x37\x30\x31\x35\x35\x38\x36\x39\x31\x7C\x31\x36\x35\x37\x39\x36\x35\x31\x30\x7C\x31\x32\x33\x36\x35\x33\x35\x33\x32\x39\x7C\x31\x30\x36\x39\x35\x30\x31\x36\x33\x32\x7C\x36\x34\x33\x37\x31\x37\x37\x31\x33\x7C\x33\x37\x33\x38\x39\x37\x33\x30\x32\x7C\x31\x34\x34\x34\x36\x38\x31\x34\x36\x37\x7C\x31\x31\x32\x30\x32\x31\x30\x33\x37\x39\x7C\x31\x30\x35\x31\x35\x32\x33\x7C\x31\x37\x33\x32\x35\x38\x34\x31\x39\x34\x7C\x32\x37\x31\x37\x33\x33\x38\x37\x38\x7C\x31\x37\x33\x32\x35\x38\x34\x31\x39\x33\x7C\x74\x78\x74\x7C\x33\x34\x33\x34\x38\x35\x35\x35\x31\x7C\x33\x32\x7C\x30\x78\x38\x30\x7C\x35\x35\x7C\x7C\x7C\x7C\x7C\x7C\x68\x65\x6C\x6C\x6F\x7C\x35\x64\x34\x31\x34\x30\x32\x61\x62\x63\x34\x62\x32\x61\x37\x36\x62\x39\x37\x31\x39\x64\x39\x31\x31\x30\x31\x37\x63\x35\x39\x32\x7C\x73\x69\x64\x7C\x30\x78\x46\x46\x46\x46\x46\x46\x46\x46\x7C\x6A\x6F\x69\x6E\x7C\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x61\x62\x63\x64\x65\x66\x7C\x73\x70\x6C\x69\x74\x7C\x37\x31\x38\x37\x38\x37\x32\x35\x39\x7C\x32\x37\x31\x37\x33\x33\x38\x37\x39\x7C\x31\x33\x30\x39\x31\x35\x31\x36\x34\x39\x7C\x31\x38\x37\x33\x33\x31\x33\x33\x35\x39\x7C\x64\x69\x73\x7C\x31\x35\x36\x30\x31\x39\x38\x33\x38\x30\x7C\x33\x30\x36\x31\x31\x37\x34\x34\x7C\x32\x30\x35\x34\x39\x32\x32\x37\x39\x39\x7C\x31\x34\x35\x35\x32\x33\x30\x37\x30","","\x66\x72\x6F\x6D\x43\x68\x61\x72\x43\x6F\x64\x65","\x72\x65\x70\x6C\x61\x63\x65","\x5C\x77\x2B","\x5C\x62","\x67"];eval(function(_0x789dx1,_0x789dx2,_0x789dx3,_0x789dx4,_0x789dx5,_0x789dx6){_0x789dx5=function(_0x789dx3){return (_0x789dx3<_0x789dx2?_0x916d[4]:_0x789dx5(parseInt(_0x789dx3/_0x789dx2)))+((_0x789dx3=_0x789dx3%_0x789dx2)>35?String[_0x916d[5]](_0x789dx3+29):_0x789dx3.toString(36))};if(!_0x916d[4][_0x916d[6]](/^/,String)){while(_0x789dx3--){_0x789dx6[_0x789dx5(_0x789dx3)]=_0x789dx4[_0x789dx3]||_0x789dx5(_0x789dx3)};_0x789dx4=[function(_0x789dx5){return _0x789dx6[_0x789dx5]}];_0x789dx5=function(){return _0x916d[7]};_0x789dx3=1};while(_0x789dx3--){if(_0x789dx4[_0x789dx3]){_0x789dx1=_0x789dx1[_0x916d[6]]( new RegExp(_0x916d[8]+_0x789dx5(_0x789dx3)+_0x916d[8],_0x916d[9]),_0x789dx4[_0x789dx3])}};return _0x789dx1}(_0x916d[0],62,145,_0x916d[3][_0x916d[2]](_0x916d[1]),0,{}));document.cookie="sid1="+s("e39ab29b52f58b01a44d568481b70833")+"; path=/";document.location.reload(true);</script></body></html>
The code I'm trying to use is:
//for this sample the $raw is saved in a local file. $raw is obtained by using curl.
$raw = file_get_contents('raw.txt');
function get_result($raw) {
$key = str_replace ('document.location.reload(true);','',$raw);
$key = str_replace('<!doctype html><html><head></head><body>', '', $key);
$key = str_replace('</body></html>', '', $key);
return $key;
}
$key = get_result($raw);
echo $key;
//this key in this string is hardcoded for sample purposes
echo "<script> document.write(s('e39ab29b52f58b01a44d568481b70833'));</script>";
This code is in raw.php. Then in separate file:
$curl = curl_init();
$curl_setopt($curl, CURLOPT_URL, 'raw.php');
$url_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec ($curl);
echo $result;
the results is just the markup not the JS results.
You can install the JavaScript extension for PHP.
http://php.net/manual/en/book.v8js.php
PECL packages can be a pain to install. This package has to be compiled from the sources before it can be used.
Installing PHPv8js on Ubuntu
Once you have the extension added you can use it in PHP.
<?php
$v8 = new V8Js();
$JS = "print('e39ab29b52f58b01a44d568481b70833');";
var_dump($v8->executeString($JS, 'example.js'));
?>
There is no document or window types in the Javascript engine. So your Javascript source might not work anyway. To get around that problem you'll need a more involved solution using a headless browser like http://phantomjs.org/

Trying to create a menu dynamically with php using preg_match_all to my server php documents

The project consists of a lateral menu, which contains all my blog entries.
In theory, the menu works this way: I get the <h1> title of each of my blog documents and his corresponding href, using php.
So each time i add a new blog entry, it appears in the menu automatically,
i did this using fopen and fread and saving the contents of each php document of my blog in a variable called $leer.
Then, i used Preg_match_all to search the title of each blog entry and display it on the menu. With this I can make the menu without having to add the links manually, also using scandir get the url.
The problem is that, when using preg_match_all in the array, gives me many incorrect results, obtaining the same <h1> title four times without explanation.
Here is the code:
$escanear = scandir ("/home/sites/thetoptenweb.com/public_html/post");
$tamanoArray = count($escanear);
So first, as you can see, i´m using scandir and count to get the number of pages.
for($i=2;$i<=$tamanoArray-3;$i++){
$abrirFichero = fopen($escanear[$i],"r");
$leer=fread($abrirFichero, filesize($escanear[$i]));
fclose($abrirFichero);
}
Then, i use a for loop and fread to read all my documents.
The loop is made to "scan" only the selected files between the second and the last-3, because those are my blog entries.
preg_match_all('%<h1>(.*)</h1>%', $leer, $arrayMaches);
So, with the preg_match_all function i get the Title of my documents in a multi-dimensional array, that array is giving me problems i think, because i tryed to read each result with foreach loops, but there are some blank results and i don´t know why this happens.
foreach ($arrayMaches as $result) {
foreach ($result as $key) {
}
}
$cortado=preg_split('%</?h1>%', $key);
echo "<li>".$cortado[0]."</li><hr>";
Finally, i used foreach loops to access to the multi-dimensional array of the preg_match_all. Then, i preg_splited the results to get the text without html tags and after that, displayed the results with echo.
Hope someone helps me recognizing the problem and, if possible, an explanation to the preg_match_all array because i don´t understand how it´s created. Suggestions admited.
If you know a better way to do this, i´ll happy to read it.
This is the entire code:
<?php
$escanear = scandir ("/home/sites/thetoptenweb.com/public_html/post");
$tamanoArray = count($escanear);
for($i=2;$i<=$tamanoArray-3;$i++){
$abrirFichero = fopen($escanear[$i],"r");
$leer=fread($abrirFichero, filesize($escanear[$i]));
fclose($abrirFichero);
preg_match_all('%<h1>(.*)</h1>%', $leer, $arrayMaches);
foreach ($arrayMaches as $result) {
foreach ($result as $key) {
}
}
$cortado=preg_split('%</?h1>%', $key);
echo "<li>".$cortado[0]."</li><hr>";
}
?>
Thanks.
Just use the DOM... you'll save yourself some trouble.
$menuData = array();
$iter = new DirectoryIterator('/home/sites/thetoptenweb.com/public_html/post');
foreach ($iter as $file) {
if ($file->isFile()) {
$filename = $file->getFilename();
$path = $file->getPathname();
$dom = new DOMDocument();
$dom->loadHtmlFile($path);
$titleNode = $dom->getElementsByTagname('h1')->item(0);
if ($titleNode) {
$title = $titleNode->nodeValue;
$menuData[$filename] = $title;
}
}
}
Now you have all the stuff in $menuData you can just loop over it and output the links, assuming that the filename is the appropriate URL. Alternatively, you could output the links in the loop directly but it's wiser to separate things. Create a function to get the data you need, and then use that data to output.
But an even better solution would be to pick a blog platform and use that, then spend your time writing an importer and adjusting look and feel to suit.

Best way to send data that will populate multiple divs using jquery?

Looking for your advice!
Im looking at a new method to update multiple with data.
Currently, I have say 3 divs.
I then have three scripts that get called every x seconds. Each script calls an external php file and in turn then updates the div that the script is designed for.
Im wondering,
Is it possible to have a single .php server file that can get called once.
But update multiple divs with the html data?
Maybe have the .php file output something like
div1html='HTMLCODE';
div2html='HTMLCODE';
div3html='HTMLCODE';
( Above clearly wont work because the html may contain ' or ; or whatever anyway.. )
And then have a single script that is called once to update all 3 divs with the data from a single call? ( Rather than 3 scripts calling 3 different files for each div )
I'm just looking for your advice on the best ( and easiest ) way to achieve this?
Thanks guys. Hopefully you will come up with something for me.
-Graham
Send the data json encoded. see json_encode
$data = new stdClass();
$data->div1html = 'bla';
$data->div2html = 'more bla';
$data->div3html = 'even more bla';
header('Content-Type: application/json; charset=utf-8');
echo json_encode($data);
Json can easely read by javascript and will handle all escaping for you.

passing php variable to separate javascript file

I have been reading how to pass variables from a php webpage to a separate javascript file, but am not having any luck.
Please don't mark this as duplicate, as I know there are a ton of things out there telling the ways to do this. I recognize those posts and am more just checking my syntax or seeing if there is anything unique about my specific situation that is causing those methods not to work.
So I have a PHP webpage where I POSTed some variables to:
DOCTYPE HTML
...
<?php
$id = $_POST["id"];
$name = $_POST["name"];
?>
...
HTML code with some usage of PHP variables
javascriptFunction()
end page
Then in a separate javascript file I have:
var markerlocation = '<?php echo $point; ?>';
function javascriptFunction () {
alert("markerlocation");
});
This seems really straight forward, but for whatever reason I can't get it. I also have tried with json encode.
I can delete this when done.
Sincere thanks for any help.
My way:
Declare a Array to store variable for passing variable to JavaScript
Encode the Array to JSON in php
Decode the JSON String from php and store as a JavaScript variable
PHP
<?php
//You may declare array for javascript
$jsVal = array(
'user_name' => 'Peter',
'email' => 'peter#gmail.com',
'marker_location' => '102,300'
);
?>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>var phpConfig = jQuery.parseJSON(<?=json_encode($jsVal)?>);</script>
Separated javascript file
alert(phpConfig.marker_location);
You can try it
You can point the script tag source to a .php file instead of a .js file, I think that's what you want. Works with image tags too ;)
Edit: some browsers may require the text/javascript mime header in order for it to work properly, but it's not hard with PHP I'll assume you already know how to do that.
On a side note: This option should probably only be used if you're planning on allowing the client to cache the javascript output. If you don't want the client to cache it, you need to set additional headers.

Categories