Skip to content

BitBook

  • Online Tools
  • Dev
  • Sysadmin
  • Reviews
  • Machine Learning
  • Home
  • Dev
  • PHP

PHP

PHP development tips, functions, and how tos

Get the PHP Version at Command Line (3 examples)

January 19, 2019 mike PHP

To find the PHP version you can combine php and grep. Get the major/minor version only 7.2 Get full version number only 7.2.10 Get the

Function to Calculate the Best Font Color for a Background Color

January 3, 2019 mike PHP

This PHP function tables a hexadecimal color code like “ff0000” and figures out what’s more color font text would be more readable, black or white.

Explode String by Any Whitespace

January 1, 2019 mike PHP

This one-liner function will turn a string into an array by its whitespace properly looking for full-width spaces and multi-byte whitespace characters.

while/foreach/for loop Skip to Next Iteration

December 31, 2018 mike PHP

If you need to skip to the next item inside of a PHP loop its simple with the continue; control keyword. You can also use

Replace Everything Inside Two Strings

December 27, 2018 mike PHP

Using the built in PHP regex function preg_replace and property encoding the two strings you’re searching for with preg_quote you can remove all of the

Strip Image EXIF Data

December 24, 2018 mike PHP

Many times you’ll want to remove the meta data on user uploaded images to your website. The meta data automatically saved to the images can

Loop Through All Properties of a PHP Object

December 13, 2018 mike PHP

Looping through all of a PHP objects properties is just as easy as an array. Output:

Validating JSON

December 11, 2018 mike PHP

The PHP json_decode function will return a strict null if the string passed into it is invalid json or it can’t parse it successfully. The

Function To Remove All Cookies For The Domain

December 6, 2018 mike PHP

This PHP function will delete all valid cookies for a domain. We’re also sanitizing the cookie variable names from invalid characters.

How to do Email Validation

December 4, 2018 mike PHP

Using the PHP filter_var function we can test email addresses for valid format and only unicode characters. Example usage below.

Posts navigation

1 2 3 Next Posts»

Bitbook

  • About
  • Privacy Policy
  • Terms of Service