Skip to content

Instantly share code, notes, and snippets.

@JonnyNineToes
JonnyNineToes / Jquery Ajax
Last active October 25, 2024 12:22
Quick template for Jquery Ajax calls
// submit is an action performed ON THE FORM ITSELF...
// probably best to give the form an ID attribute and refer to it by that
$('form').submit( function (event) {
// prevent the usual form submission behaviour; the "action" attribute of the form
event.preventDefault();
// validation goes below...
// now for the big event
$.ajax({
// the server script you want to send your data to
@JonnyNineToes
JonnyNineToes / PHP Title Case
Last active June 28, 2023 07:48
PHP Title Case function
function titleCase($string) {
//reference http://grammar.about.com/od/tz/g/Title-Case.htm
// The below array contains the most commonly non-capitalized words in title casing - I'm not so sure about the commented ones that follow it...
$minorWords = array('a','an','and','as','at','but','by','for','in','nor','of','on','or','per','the','to','with'); // but, is, if, then, else, when, from, off, out, over, into,
// take the input string, trim whitespace from the ends, single out all repeating whitespace
$string = preg_replace('/[ ]+/', ' ', trim($string));
// explode string into array of words
$pieces = explode(' ', $string);
// for each element in array...
for($p = 0; $p <= (count($pieces) - 1); $p++){
@JonnyNineToes
JonnyNineToes / PHP Get TLD
Last active December 22, 2015 05:39
Get top level domain with PHP. The code should return ".com", depending on what website you're on, and can be customized for other top level domains (useful for development if you have a ".dev" domain set up on your local machine).
end(explode('.', $_SERVER['SERVER_NAME']))