Created
May 15, 2012 05:25
-
-
Save geeksunny/2699331 to your computer and use it in GitHub Desktop.
stringTools: an interface to quickly automate common string conversion tasks.
This file contains 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
<?php | |
/** | |
* StringTools | |
* Justin Swanson | |
* www.github.com/geeksunny | www.faecbawks.com | www.h4xful.net | |
* | |
* An example of this script can be found at http://beta.h4xful.net/tools/string_tools.php | |
*/ | |
if (isset($_POST['mode'])) | |
{ | |
if ($_POST['mode'] == 'relDate') | |
{ | |
$modifier = ($_POST['modifier'] == '-') ? $_POST['modifier'] : '+'; | |
$output = strtotime($_POST['target']." ".$modifier.$_POST['days']." days"); | |
exit(@date("F d, Y",$output)."<br><br>or<br><br>".@date("Y-m-d",$output)); | |
} | |
elseIf ($_POST['mode'] == 'relDateCode') | |
{ | |
$modifier = ($_POST['modifier'] == '-') ? $_POST['modifier'] : '+'; | |
$difference = strtotime($_POST['input']) - time(); | |
exit("date('Y-m-d H:i:s', time() ".$modifier." $difference);"); | |
} | |
elseif ($_POST['mode'] == 'timeStamp') | |
{ | |
function isValidTimeStamp($timestamp) | |
{ | |
return ((string) (int) $timestamp === $timestamp) | |
&& ($timestamp <= PHP_INT_MAX) | |
&& ($timestamp >= ~PHP_INT_MAX); | |
} | |
if (isValidTimeStamp($_POST['string'])) | |
exit(@date("F d, Y",$_POST['string'])."<br><br>or<br><br>".@date("Y-m-d",$_POST['string'])); | |
else | |
exit((string)strtotime($_POST['string'])); | |
} | |
elseif ($_POST['mode'] == 'ip2long') | |
{ | |
$output = (ip2long($_POST['string'])) ? ip2long($_POST['string']) : long2ip($_POST['string']); | |
exit((string)$output); | |
} | |
} | |
?> | |
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> | |
<title>stringTools</title> | |
<style type="text/css"> | |
/* Color Palette: http://www.colourlovers.com/palette/1262230/A_Nod_to_Odd */ | |
body { | |
background-color: #EFF4F4; | |
color: #7DB4B5; | |
font-family: Arial,sans-serif; | |
} | |
h1 { | |
border-bottom: solid 1px #7DB4B5; | |
} | |
.tool { | |
margin-left: 25px; | |
} | |
.tool div { | |
padding: 20px; | |
} | |
h2 { | |
border-bottom: dotted 1px #7DB4B5; | |
} | |
.output { | |
background-color: #735B7F; | |
font-weight: bold; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>stringTools</h1> | |
<div class="tool"> | |
<h2>Relative Date</h2> | |
<div> | |
What is the date for | |
<input type="text" id="relDateNum" value="1" style="width:30px; text-align:center;"> | |
day(s) | |
<select id="relDateModifier"> | |
<option value="-">before</option> | |
<option value="+">after</option> | |
</select> | |
<input type="text" id="relDateTarget" value="<?=date("F d, Y")?>" style="text-align:center;"> | |
<input type="submit" id="relDateSubmit"> | |
</div> | |
<div class="output"> | |
<span id="relDateOutput"><?=date("F d, Y",strtotime(date("Y-m-d")." -1 day"))?><br><br>or<br><br><?=date("Y-m-d",strtotime(date("Y-m-d")." -1 day"))?></span> | |
</div> | |
</div> | |
<div class="tool"> | |
<h2>Relative Date/Time Code</h2> | |
<div> | |
Generate code to find out | |
<input type="text" id="relDateCodeInput" value="36 hours" style="text-align:center;"> | |
<select id="relDateCodeModifier"> | |
<option value="-">before</option> | |
<option value="+">after</option> | |
</select> | |
right now. | |
<input type="submit" id="relDateCodeSubmit"> | |
</div> | |
<div class="output"> | |
<span id="relDateCodeOutput"><?php | |
$difference = strtotime("36 hours") - time(); | |
echo "date('Y-m-d H:i:s', time() - $difference);"; | |
?></span> | |
</div> | |
</div> | |
<div class="tool"> | |
<h2>Date string <-> Unix timestamp Conversion</h2> | |
<div> | |
Enter a date string OR a Unix time stamp: | |
<input type="text" id="timeStampInput" value="<?=date("F d, Y")?>" style="text-align:center;"> | |
<input type="submit" id="timeStampSubmit"> | |
</div> | |
<div class="output"> | |
<span id="timeStampOutput"><?=(string)strtotime(date("F d, Y"))?></span> | |
</div> | |
</div> | |
<div class="tool"> | |
<h2>IP Address <-> Long format Conversions</h2> | |
<div> | |
Enter an IP address OR long format address: | |
<input type="text" id="ipAddressInput" value="<?=$_SERVER['REMOTE_ADDR']?>" style="text-align:center;"> | |
<input type="submit" id="ipAddressSubmit"> | |
</div> | |
<div class="output"> | |
<span id="ipAddressOutput"><?=ip2long($_SERVER['REMOTE_ADDR'])?></span> | |
</div> | |
</div> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() | |
{ | |
$('#relDateSubmit').live('click',function(e) | |
{ | |
e.preventDefault(); | |
var postString = "mode=relDate&days="+$('#relDateNum').val()+"&modifier="+$('#relDateModifier').val()+"&target="+$("#relDateTarget").val(); | |
console.log(postString); | |
$.ajax({ | |
type: "POST", | |
url: location.href, | |
data: postString, | |
success: function(data) { | |
$("#relDateOutput").fadeOut(400,function() | |
{ | |
$("#relDateOutput").html(data); | |
$("#relDateOutput").fadeIn(400); | |
}); | |
}, | |
error: function() { | |
alert("An error has occurred... (AJAX)"); | |
} | |
}); | |
}); | |
$('#relDateCodeSubmit').live('click',function(e) | |
{ | |
e.preventDefault(); | |
var postString = "mode=relDateCode&modifier="+$('#relDateCodeModifier').val()+"&input="+$('#relDateCodeInput').val(); | |
console.log(postString); | |
$.ajax({ | |
type: "POST", | |
url: location.href, | |
data: postString, | |
success: function(data) { | |
$("#relDateCodeOutput").fadeOut(400,function() | |
{ | |
$("#relDateCodeOutput").html(data); | |
$("#relDateCodeOutput").fadeIn(400); | |
}); | |
}, | |
error: function() { | |
alert("An error has occurred... (AJAX)"); | |
} | |
}); | |
}); | |
$('#timeStampSubmit').live('click',function(e) | |
{ | |
e.preventDefault(); | |
var postString = "mode=timeStamp&string="+$("#timeStampInput").val(); | |
console.log(postString); | |
$.ajax({ | |
type: "POST", | |
url: location.href, | |
data: postString, | |
success: function(data) { | |
$("#timeStampOutput").fadeOut(400,function() | |
{ | |
$("#timeStampOutput").html(data); | |
$("#timeStampOutput").fadeIn(400); | |
}); | |
}, | |
error: function() { | |
alert("An error has occurred... (AJAX)"); | |
} | |
}); | |
}); | |
$('#ipAddressSubmit').live('click',function(e) | |
{ | |
e.preventDefault(); | |
var postString = "mode=ip2long&string="+$("#ipAddressInput").val(); | |
console.log(postString); | |
$.ajax({ | |
type: "POST", | |
url: location.href, | |
data: postString, | |
success: function(data) { | |
$("#ipAddressOutput").fadeOut(400,function() | |
{ | |
$("#ipAddressOutput").html(data); | |
$("#ipAddressOutput").fadeIn(400); | |
}); | |
}, | |
error: function() { | |
alert("An error has occurred... (AJAX)"); | |
} | |
}); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment