Category: PHP

PHP Functions

Randomly Generate Readable Password

function auth_pwgen(){ $pw = ”; $c = ‘bcdfghjklmnprstvwz’; //consonants except hard to speak ones $v = ‘aeiou’; //vowels $a = $c.$v; //both //use two syllables… for($i=0;$i < 2; $i++){ $pw .= $c[rand(0, strlen($c)-1)]; $pw .= $v[rand(0, strlen($v)-1)]; $pw .= $a[rand(0, strlen($a)-1)]; } //... and add a nice number $pw .= rand(10,99); return $pw; }

Read more

Disable Payment Method Based on Country Woocommerce PHP

// Disable gateway based on country function payment_gateway_disable_country( $available_gateways ) { global $woocommerce; if ( isset( $available_gateways[‘cod’] ) && $woocommerce->customer->get_country() <> ‘IN’ ) { unset( $available_gateways[‘cod’] ); } return $available_gateways; } add_filter( ‘woocommerce_available_payment_gateways’, ‘payment_gateway_disable_country’ );

Read more
PHP Functions

Woocommerce List all Available Payment Gateways

$available_gateways = WC()->payment_gateways->get_available_payment_gateways();

Read more

Get Youtube Thumbnails with PHP or Html

Each YouTube video has 4 generated images. They are predictably formatted as follows: http://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg http://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg http://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg http://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (ie. one of 1.jpg, 2.jpg, 3.jpg) is: http://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg For the high quality version of the thumbnail use a url similar […]

Read more
PHP Functions

How to a Print to a Local or Network Printer with PHP and Linux Command Line

Easy way to print from php or just plain command line. exec(“lpr [ options ] [ filename … ]”); Gettin a little fancy. cat thesis.txt | lpr Another example exec(“lpr -P printer -r filename.txt”); Read more in at this Link

Read more
PHP Functions

How to Split an Array into a String with PHP

$myArray = explode(‘,’, $myString);

Read more
PHP Functions

PHP Code for Replacing Characters in a String or Variable

str_replace(‘”‘, “”, $string); preg_replace(“//”, “”, $string); C-style quotes: preg_replace(“/\/\/.*?\n/”, “\n”, $string); CSS-style quotes: preg_replace(“/\/*.*?\*\//”, “”, $string); bash-style quotes: preg-replace(“/#.*?\n/”, “\n”, $string);

Read more
PHP Functions

Split PHP String into Multiple Variables Made Easy

Like a Glove….

Read more
PHP Functions

Adding or Subtracting Time to/from MYSQL Formatted Timestamp in PHP

Just replace “+1 day” with what ever you need to add. ex “+1 year, +1 day” etc. Have fun. $date = date(“Y-m-d”,strtotime(“+1 day”));

Read more
PHP Functions

Easy Way to Convert Month Number into Month Names with PHP

And here it is.

Read more