Created
November 27, 2016 23:44
-
-
Save ArseniyShestakov/39eb567f21fbf3d892865a9b9033836c to your computer and use it in GitHub Desktop.
Some crappy parser in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<meta name="referrer" content="no-referrer" /> | |
<form action="mAx-knigi.php" method="post"> | |
URL: <input type="text" name="url"><br> | |
<input type="submit" value="Submit"> | |
</form><br><br> | |
<?php | |
if(isset($_POST['url']) && strlen($_POST['url']) > 10) | |
{ | |
$url = parse_url($_POST['url'], PHP_URL_PATH); | |
$page = file_get_contents('https://domain/'.$url); | |
if(strlen($page) < 100) | |
exit('ERROR1: Book page download failed'); | |
preg_match_all('~\$\(document\)\.audioPlayer\(([0-9]+),0\);~', $page, $m); | |
if(isset($m[1][0])) | |
{ | |
$id = $m[1][0]; | |
$pagerest = file_get_contents('https://domain/rest/bid/'.$id); | |
if(strlen($pagerest) < 50) | |
exit('ERROR2: List page download failed!'); | |
$json = json_decode($pagerest, true); | |
print_r($json, true); | |
if(is_array($json) && sizeof($json)) | |
{ | |
foreach($json as $entry) | |
{ | |
echo "<a href='".$entry['mp3']."'>".$entry['title']."</a><br>"; | |
} | |
echo '<br><br><textarea name="comment" rows="20" cols="160">'; | |
foreach($json as $entry) | |
{ | |
$encoded_url = preg_replace_callback('#://([^/]+)/([^?]+)#', function ($match) { | |
return '://' . $match[1] . '/' . join('/', array_map('rawurlencode', explode('/', $match[2]))); | |
}, $entry['mp3']); | |
echo $encoded_url.PHP_EOL; | |
} | |
echo '</textarea>'; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment