I need to remove empty lines when reading a file, and skip unnecessary lines to pass only the URL of the address to the parse_url function
File contents:
http: // shurik: qwerty@my.site.com: 9191 / documents.php? documentId = 128 & type = pdf # content
http: // shurik: qwerty@my.site.com: 9191 / 211.php? photoId = 128
http://www.google.com.ua:8080/catalog/folder/myname.php?answer=123&url=www.iai.ua
My code is:
<html> <head> </head> <body> <form method="get" action="1.php"> <br /> <p>Путь к файлу: <input name="file" type="text" size="50" tabindex="1" > <input type="submit" value="Ок" tabindex="2"></p> </form> <?php if (isset($_GET['file'])/*$_GET['submit']="Ok"*/) { echo "<div align=\"center\">\n<h2>Результаты:</h2>\n<div align=\"left\" style=\"width:75%\">\n"; $file = stripslashes(htmlspecialchars(escapeshellcmd(trim($_GET['file'])))); echo "Открытие файла: \"{$file}\"..."; if (file_exists($file)) { echo " файл найден!\n"; echo "<h3>Содержимое файла:</h3>"; $fp = file($file); $flines = count($fp); $arr = array(); for ($i = 0; $i < $flines; $i++) { echo $fp[$i]."<br>"; $url = $fp[$i]; $t = array ( 'scheme' => 'Протокол', 'host' => 'Хост', 'port' => 'Порт', 'user' => 'Юзер', 'pass' => 'Пароль', 'path' => 'Путь к файлу', 'query' => 'Параметры запроса', 'fragment' => 'Фрагмент' ); $arr = parse_url($url); foreach ($arr as $key => $val) { echo $t[$key].': '. $val."<br>"; } } } else { echo " файл не найден!\n"; } echo "</div>\n</div>\n"; } ?> </body> </html>
But it turns out only this way:
And the __ sign in fragment is superfluous, where does it come from?