twmbx / Recipe

Collection of PHP Functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Recipe 📖

####Collection of PHP Functions

StyleCI


Table of Contents


###Quick Start Run in your terminal:

composer require ngfw/recipe

Create new file and start using the Recipes

<?php

require "vendor/autoload.php";

use ngfw\Recipe as Recipe;

$suggestion = Recipe::getKeywordSuggestionsFromGoogle("home");

print_r($suggestion);
//
//Array
//(
//    [0] => home depot
//    [1] => home goods
//    [2] => home depot near me
//    [3] => homes for sale
//    [4] => homeaway
//    [5] => homes for rent
//    [6] => home advisor
//    [7] => home depot credit card
//    [8] => home depot coupons
//    [9] => homeland
//)

###Favicon Getting remote website Favicon:

$favIcon = \ngfw\Recipe::getFavicon("http://youtube.com/");

echo $favIcon; 
// outputs: <img src="http://www.google.com/s2/favicons?domain=youtube.com/"  />

Getting remote website Favicon with HTML attributes:

$favIcon = \ngfw\Recipe::getFavicon(
          "http://youtube.com/", 
          array(
            "class" => "favImg"
          )
);
echo $favIcon; 
//outputs: <img src="http://www.google.com/s2/favicons?domain=youtube.com/" class="favImg" />
            

###QRcode Generating QR code

$QRcode = \ngfw\Recipe::getQRcode("ngfw Recipe");
echo $QRcode;  
//outputs: <img src="http://chart.apis.google.com/chart?chs=150x150&cht=qr&chl=ngfw+Recipe"  />

Generating QR code and adding HTML attributes:

$QRcode = \ngfw\Recipe::getQRcode(
    "ngfw Recipe",
    $width = 350, 
    $height = 350, 
    $attributes = array(
        "class" => "QRCode"
    )
);
echo $QRcode;  
// outputs: <img src="http://chart.apis.google.com/chart?chs=350x350&cht=qr&chl=ngfw+Recipe" class="QRCode" />

###File extension

$ext = \ngfw\Recipe::getFileExtension(__FILE__); // replace '__FILE__' with your filename
echo $ext; 
//outputs: php

###Gravatar Getting Gravatar:

$Gravatar = \ngfw\Recipe::getGravatar("gejadze@gmail.com");
echo $Gravatar;
// outputs: <img src="http://www.gravatar.com/avatar.php?gravatar_id=9d9d478c3b65d4046a84cf84b4c8bf46&default=mm&size=80&rating=g" width="80px" height="80px"  />

https://www.gravatar.com/avatar.php?gravatar_id=9d9d478c3b65d4046a84cf84b4c8bf46&default=mm&size=80&rating=g

Getting Gravatar with HTML attributes:

$Gravatar = \ngfw\Recipe::getGravatar(
    "gejadze@gmail.com",
    $size = 200,
    $default = 'monsterid',
    $rating = 'x',
    $attributes = array(
        "class" => "Gravatar"
    )
);
ehco $Gravatar;
//Outputs: <img src="http://www.gravatar.com/avatar.php?gravatar_id=9d9d478c3b65d4046a84cf84b4c8bf46&default=monsterid&size=200&rating=x" width="200px" height="200px" class="Gravatar" />'

NG Gravatar

###Creating Link Tags Simple Link:

$linkTags = \ngfw\Recipe::createLinkTag("google.com");
echo $linkTags;   
//outputs: <a href="google.com">google.com</a>

Link with title:

$linkTags = \ngfw\Recipe::createLinkTag("google.com", "Visit Google");
echo $linkTags;   
//outputs: <a href="google.com" title="Visit Google" >Visit Google</a>

Link with title and HTML attributes:

$linkTags = \ngfw\Recipe::createLinkTag("google.com", "Visit Google", array(
    "class" => "outgoingLink"
));
echo $linkTags;   
//outputs: <a href="google.com" title="Visit Google" class="outgoingLink">Visit Google</a>

Validate email address

$isValid = \ngfw\Recipe::validateEmail("user@gmail.com");
var_dump($isValid);
// outputs: true (bool)

Validate URL

$isValid = \ngfw\Recipe::validateURL("http://github.com/");
var_dump($isValid);
// outputs: true (bool)

RSS Reader

$rssArray = \ngfw\Recipe::rssReader("https://github.com/ngfw/Recipe/commits/master.atom");
var_dump($rssArray);
// Outputs feed as an array

Object to Array

$obj = new stdClass;
$obj->foo = 'bar';
$obj->baz = 'qux';
$array = \ngfw\Recipe::objectToArray($obj);
var_dump($array);

// outputs:
// array(2) {
//   ["foo"]=>
//   string(3) "bar"
//   ["baz"]=>
//   string(3) "qux"
// }

###Array to Object

$array = array(
    "foo" => "bar",
    "baz" => "qux",
);
$obj = \ngfw\Recipe::arrayToObject($array);
// outputs:
// object(stdClass)#15 (2) {
//   ["foo"]=>
//   string(3) "bar"
//   ["baz"]=>
//   string(3) "qux"
// }

###Array to String

$array = array(
    "foo" => "bar",
    "baz" => "qux",
);
$string = Recipe::arrayToString($array);
echo $string;
// outputs: foo="bar" baz="qux"

###HEX to RGB

$rgb = \ngfw\Recipe::hex2rgb("#FFF");
echo $rgb;
// outputs: rgb(255, 255, 255)

###RGB to HEX

$hex = \ngfw\Recipe::rgb2hex("rgb(123,123,123)");
// outputs: #7b7b7b

###Generate Random Password

$randomPass = \ngfw\Recipe::generateRandomPassword(10);
echo $randomPass;
// outputs: 10 random character string 

###Simple Encode

$encodedString = \ngfw\Recipe::simpleEncode("php recipe");
echo $encodedString;
// outputs: qcnVhqjKxpuilw==

###Simple Decode

$decodedString = \ngfw\Recipe::simpleDecode("qcnVhqjKxpuilw==");
echo $decodedString;
// outputs: php recipe

###Generate Server Specific Hash

$serverHash = \ngfw\Recipe::generateServerSpecificHash();
echo $serverHash;
// outputs: d41d8cd98f00b204e9800998ecf8427e

###Detect HTTPS This method checks for $_SERVER['HTTPS']

$isHttps = \ngfw\Recipe::isHttps();
var_dump($isHttps);
// outputs: bool

###Detect AJAX This method checks for $_SERVER['HTTP_X_REQUESTED_WITH']

$isAjax = \ngfw\Recipe::isAjax();
var_dump($isAjax);
// outputs: bool

###Check if number is odd

$isNumberOdd = \ngfw\Recipe::isNumberOdd(5);
// outputs: bool

###Check if number is even

$isNumberEven = \ngfw\Recipe::isNumberEven(8);
var_dump($isNumberEven);
// outputs: bool

###Get Current URL

$currentURL = \ngfw\Recipe::getCurrentURL();
var_dump($currentURL);
// outputs: current Request URL

###Get Client IP

$ClientsIP = \ngfw\Recipe::getClientIP();
echo $ClientsIP;
//OR 
// Return Proxy IP if user is behind it
//$ClientsIP = \ngfw\Recipe::getClientIP("HTTP_CLIENT_IP"); //'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED', ...
// outputs: IP address

###Detect Mobile

$isMobile = \ngfw\Recipe::isMobile();
var_dump($isMobile);
// outputs: true or false

###Get Browser

$Browser = \ngfw\Recipe::getBrowser();
echo $Browser
// outputs: Browser Details

###Get Client Location

$user_location = \ngfw\Recipe::getClientLocation();
echo $user_location;
// outputs: Users Location

###Number To Word conversion

$number = "864210";
$number_in_words = \ngfw\Recipe::numberToWord($number);
echo $number_in_words;
// outputs: eight hundred and sixty-four thousand, two hundred and ten

###Seconds To Text

$seconds = "864210";
$number_in_words = \ngfw\Recipe::numberToWord($seconds);
echo $number_in_words;
// outputs: 1 hour and 10 seconds
// \ngfw\Recipe::secondsToText($seconds, $returnAsWords = true);
// will return: one hour and ten seconds

###Minutes To Text

$minutes  = 60 * 24 * 2;
$duration = \ngfw\Recipe::minutesToText($minutes);
echo $duration;
// outputs: 2 days
// \ngfw\Recipe::minutesToText($minutes, $returnAsWords = true);
// will return: two days

###Hours To Text

$hours    = 4.2;
$duration = \ngfw\Recipe::hoursToText($hours);
echo $duration;
// outputs: 4 hours and 12 minutes
// \ngfw\Recipe::hoursToText($hours, $returnAsWords = true);
// will return: four hours and twelve minutes

###Shorten String

$string        = "The quick brown fox jumps over the lazy dog";
$shortenString = \ngfw\Recipe::shortenString($string, 20);
// output: The quick brown f...
// \ngfw\Recipe::shortenString($string, 20, $addEllipsis = false);
// output: "The quick brown fox ", NOTE last space
// \ngfw\Recipe::shortenString($string, 20, $addEllipsis = false, $wordsafe = true);
// output: "The quick brown fox", NOTE, will not break in the middle of the word

###CURL

Simple GET example:

$data = \ngfw\Recipe::curl("https://api.ipify.org");
var_dump($data);
// outputs: Curl'ed Data

POST Example:

$CurlPOST = \ngfw\Recipe::curl("http://jsonplaceholder.typicode.com/posts", $method = "POST", $data = array(
    "title"  => 'foo',
    "body"   => 'bar',
    "userId" => 1,
));

Custom Headers:

$curlWithHeaders = \ngfw\Recipe::curl("http://jsonplaceholder.typicode.com/posts", $method = "GET", $data = false, $header = array(
    "Accept" => "application/json",
), $returnInfo = true);
// NOTE $returnInfo argument 
// Result will be returned as an array, $curlWithHeaders={
//  info => containing curl information, see curl_getinfo()
//  contents  => Data from URL
//}

###Expand Short URL

$shortURL = "https://goo.gl/rvDnMX";
$expandedURL = \ngfw\Recipe::expandShortUrl($shortURL);
echo $expendedURL;
// outputs: https://github.com/ngfw/Recipe

###Get Alexa Rank

$AlexaRank = \ngfw\Recipe::getAlexaRank("github.com");
echo $AlexaRank;
// outputs: Current alexa ranking as position number (example: 52)

###Get Google PageRank

$GoogleRank = \ngfw\Recipe::getGooglePageRank("github.com");
echo $GoogleRank;
// outputs: Current google page ranking

###Shorten URL

$TinyUrl = \ngfw\Recipe::getTinyUrl("https://github.com/ngfw/Recipe");
echo $TinyUrl;
// outputs: http://tinyurl.com/h2nchjh

###Get Keyword Suggestions From Google

$suggestions = \ngfw\Recipe::getKeywordSuggestionsFromGoogle("Tbilisi, Georgia");
var_dump($suggestions);
// outputs: 
//array(10) {
//  [0]=>
//  string(15) "tbilisi georgia"
//  [1]=>
//  string(22) "tbilisi georgia hotels"
//  [2]=>
//  string(19) "tbilisi georgia map"
//  [3]=>
//  string(20) "tbilisi georgia time"
//  [4]=>
//  string(23) "tbilisi georgia airport"
//  [5]=>
//  string(23) "tbilisi georgia weather"
//  [6]=>
//  string(24) "tbilisi georgia language"
//  [7]=>
//  string(24) "tbilisi georgia zip code"
//  [8]=>
//  string(20) "tbilisi georgia news"
//  [9]=>
//  string(28) "tbilisi georgia airport code"
//}

###WIKI Search

$wiki = \ngfw\Recipe::wikiSearch("Tbilisi");
var_dump($wiki);
// outputs: data from wikipedia

###Notification

$notification = \ngfw\Recipe::notification("Test Successful");
echo $notification;
// outputs: <div style="display: block;padding: 0.5em;border: solid 1px;border-radius: 0.125em;margin-bottom: 1em; border-color: #a6d9f2;color: #0a5276;background-color: #e7f6fd;"  role="alert">Test Successful</div>
// NOTE: possible notifications types: success, warning, error and info
// Type is passed as a second parameter 

###Auto Embed

$string = "Checkout Solomun, Boiler Room at https://www.youtube.com/watch?v=bk6Xst6euQk";
echo \ngfw\Recipe::autoEmbed($string);
// outputs:
// Checkout Solomun, Boiler Room at<iframe width="560" height="315" src="https://www.youtube.com/embed/bk6Xst6euQk?feature=oembed" frameborder="0" allowfullscreen></iframe>
// supported providers are: youtube.com, blip.tv, vimeo.com, dailymotion.com, flickr.com, smugmug.com, hulu.com, revision3.com, wordpress.tv, funnyordie.com, soundcloud.com, slideshare.net and instagram.com 

###Make Clickable Links

$string = "Check PHP Recipes on https://github.com/ngfw/Recipe";
$clickable = \ngfw\Recipe::makeClickableLinks($string);
echo $clickable;
// outputs:
// Check PHP Recipes on <a href="https://github.com/ngfw/Recipe" >https://github.com/ngfw/Recipe</a>

###Debug var_dump() alternative

$string = "Test me";
\ngfw\Recipe::debug($string);

About

Collection of PHP Functions

License:MIT License


Languages

Language:PHP 100.0%