URL Info Extractor

Written by @m_k_amin 20 November 2012

This script is an example of working with strings. It gets a URL name and extracts all parts of it such as protocol, domain parts, other parts, the page name and input variables. You can improve your skill of working with strings by this code. Enjoy!

Code Snippet:

                                                
                                                <!-- this script is provided by www.phpfreecode.com coded by: Kerixa Inc. -->
<!-- This Script is from www.phpfreecpde.com, Coded by: Kerixa Inc-->
<?php
$url='';
if (isset($_POST['Submit']))
	$url=$_POST['URL'];
//var_dump($url);
$i=strpos($url,'://');
$htt=substr($url,0,$i);
if ($htt=="") $htt= 'No HTTP';
$site=substr($url,$i+3);
$part=explode('/',$site);
$domain=$part[0];
$dpart=explode('.',$domain);
$domainparts='';
for($k=0;$k<count($dpart);$k++)
	$domainparts.= $dpart[$k].', ';
$domainparts=substr($domainparts,0,strlen($domainparts)-2);
$pages='';
for($k=1;$k<=count($part)-2;$k++)
	$pages.=$part[$k].', ';
$pages=substr($pages,0,strlen($pages)-2);
$i=strpos($part[count($part)-1],'?');
$lastpage=substr($part[count($part)-1],0,$i);
$inputs=substr($part[count($part)-1],$i+1);

?>

<form method="post">
<table style="border: 1px solid #000000;width: 543px" align="center">
	<tr>
		<td style=" padding: 5px; font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; width: 179px; color: #2214B9;border-style: solid;border-width: 1px;">
		<strong>URL</strong></td>
		<td style="padding: 5px;font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; color: #2214B9;border-style: solid;border-width: 1px; width: 432px;">
			<input name="URL" style="padding: 8px;width: 235px; height: 41px; font-family: 'Times New Roman', Times, serif; font-size: 14pt; margin-left: 0px" value="<?php echo $url ?>">
			<input name="Submit" style="width: 86px; height: 41px; margin-top: 0px" type="submit" value="Extract"></td>
	</tr>
	<tr>
<?php if (isset($_POST['Submit'])){ ?>
	<td style="padding: 5px; font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; width: 179px; color: #2214B9;border-style: solid;border-width: 1px;">
		<strong>Protocol</strong></td>
	<td style="padding: 5px;font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; color: #2214B9;border-style: solid;border-width: 1px; width: 432px;">
			<?php echo $htt ?></td>
	</tr>
	<tr>
	<td style="padding: 5px; font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; width: 179px; color: #2214B9;border-style: solid;border-width: 1px;">
		<strong>Domain Parts</strong></td>
	<td style="padding: 5px;font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; color: #2214B9;border-style: solid;border-width: 1px; width: 432px;">
		<?php echo $domainparts ?></td>
	</tr>
	<tr>
	<td style="padding: 5px; font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; width: 179px; color: #2214B9;border-style: solid;border-width: 1px;">
		<strong>Parts</strong></td>
	<td style="padding: 5px;font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; color: #2214B9;border-style: solid;border-width: 1px; width: 432px;">
		<?php echo $pages ?></td>
	</tr>
	<tr>
	<td style="padding: 5px; font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; width: 179px; color: #2214B9;border-style: solid;border-width: 1px;">
		<strong>Page Name</strong></td>
	<td style="padding: 5px;font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; color: #2214B9;border-style: solid;border-width: 1px; width: 432px;">
		<?php echo $lastpage ?></td>
	</tr>
	<tr>
	<td style="padding: 5px; font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; width: 179px; color: #2214B9;border-style: solid;border-width: 1px;">
		<strong>Inputs</strong></td>
	<td style="padding: 5px;font-family: 'Times New Roman', Times, serif;font-size: 17pt;text-align: left; color: #2214B9;border-style: solid;border-width: 1px; width: 432px;">
		<?php echo $inputs ?></td>
	</tr>
<?php } ?>
</table>
</form>
<div style="text-align: center">
	<font face="Tahoma"><a target="_blank" href="http://www.phpfreecode.com/">
	<span style="font-size: 8pt; text-decoration: none">PHP Free Code</span></a></font>
</div>
<a target='_blank' href='www.phpfreecode.com' style='font-size: 8pt; text-decoration: none'>Php Best Codes</a>                                                
                                            

Example:


About @m_k_amin

This user is pending a biography.

M
TRENDING POST
1
2
3
4
5
VISITORS
Online Users: 12
Recent Members: Manaakividuinfo.com, karticksv, sava, tinatina, sandiegostrippersinsandiego
advertisement 2