Skip to main content

Posts

Showing posts with the label PHP

PHP encrypt and decrypt

 <?php $string_to_encrypt="Test"; $password="password"; $encrypted_string=openssl_encrypt($string_to_encrypt,"AES-128-ECB",$password); $decrypted_string=openssl_decrypt($encrypted_string,"AES-128-ECB",$password); echo $encrypted_string; echo "\n.............\n"; echo $decrypted_string; $data = [    ]; echo "<br/>"; $password = "siddhu**7**0"; foreach($data as $d) { echo $d."\n"; echo "<br/>"; echo openssl_decrypt($d,"AES-128-ECB",$password); echo "<br/>"; echo "<br/>"; } ?>

Select 2 options with live examples

Select2 options Select2 gives you a customizable select box with support for searching, tagging, remote data sets, infinite scrolling, and many other highly used options. Here I prepared for all set of examples with sample codes, You don't need to read entire document to do this See the Pen Select2 examples from Codesponsors.com by Codesponsors ( @Codesponsors ) on CodePen .

How to check business hour, non-business hour, weekend and holiday using PHP?

At times, you may have faced problem in finding the solution where you have date&time as input and should check whether the date falls on Weekend, Holiday or Weekday & the time is between Business hours or Non-business hours. Here is a code snippet to find the input(i.e date and time) comes under Holiday, Weekend, Business Hours and Non-Business Hours. <?php # Getting Workday Type # Suppose I consider the date with time 2018-12-25 19:28:00 # You need to find out this date&time among the list of the Business hour, Non-business hour, Weekends, And Holidays # Holidays list & Weekdays are in Array # Consider Business works 9:00 AM to 6:00PM $holidays = ['01-01-2018','25-12-2018','10-07-2019','15-08-2019']; $weekdays = [0,1,2,3,4,5,6]; //['mon','tue','wed','thu','fri'] $input_date = '2018-12-25 19:28:00'; //'YYYY-MM-DD h:i:s' $business_start_time = "09:00";

How to calculate per hour cost using PHP?

As we know so many times. You need to calculate an hour price in your PHP applications. Here I coded a small script to achieve it. <?php # Hours to cost Calculation # My hour cost is = 200 # Suppose I consider total hours 03:20:45 # Formula $total_cost = ($amount_per_hour*($consumed_hours*3600 + $consumed_mins*60 + $consumed_secs))/3600; $h = 3; $m = 20; $s = 45; $amount_per_hour = 200; $consumed_hours = $h; $consumed_mins = $m; $consumed_secs = $s; $total_cost = ($amount_per_hour*($consumed_hours*3600 + $consumed_mins*60 + $consumed_secs))/3600; echo $total_cost; //output: 669.16666666667 ?>

Debug the PHP Application with Xdebug, WinCacheGrind and Windows

The Xdebug extension encourages you to troubleshoot your content by giving a great deal of profitable investigate data. Installing Xdebug for XAMPP with PHP 7.x Basic Requirements XAMPP for Windows: https://www.apachefriends.org/download.html The VC14 builds require to have the Visual C++ Redistributable for Visual Studio 2015 x86 or x64 installed The VC15 builds require to have the Visual C++ Redistributable for Visual Studio 2017 x64 or x86 installed Setup Download Xdebug for: PHP 7.0.x: https://xdebug.org/files/php_xdebug-2.5.5-7.0-vc14.dll PHP 7.1.x: https://xdebug.org/files/php_xdebug-2.5.5-7.1-vc14.dll PHP 7.2.x: https://xdebug.org/files/php_xdebug-2.6.0-7.2-vc15.dll Copy the file php_xdebug-2.6.0-7.2-vc15.dll to C:\xampp\php\ext Open the file C:\xampp\php\php.ini with Notepad++ Disable output buffering: output_buffering = Off Scroll down to the [ XDebug ] section (or create it) and copy this lines [XDebug] zend_extension = "c:\xamp

Business hours calculation using PHP

Most of ticketing alert projects needed SLA calculation to exclude holidays and weekends or Off business hours. First of all, let us take a look at types of SLA we need to calculate. For instance, few companies will work 24/7 shifts and 8x5, 8x7 etc. So we need to consider business hours. In this example, I'm considering business hours which starts at 09:00 AM and ends at 06:00 PM. Also, using this code we can calculate 24/7 too. Let's consider business hours started at 9:00 AM to 18:00 PM without weekends. Now, take the actual work start period and end period.                                                       Demo <?php $incident_work_started = '2018-09-12 09:28:07'; $incident_work_ended = '2018-09-19 17:45:00'; $totalHours = round(get_working_hours($incident_work_started,$incident_work_ended),2)."\n"; echo "Total hours: ".$totalHours; function get_working_hours($work_started,$work_ended) { //

IST to EST time conversion in PHP

IST to EST time conversion  using PHP <?php $dt = new DateTime('2011-02-22 16:15:20', new DateTimeZone('Asia/Kolkata')); echo $dt->format('r') . PHP_EOL; $dt->setTimezone(new DateTimeZone('US/Eastern')); echo $dt->format('r') . PHP_EOL; //Second example $time = new DateTime('now', new DateTimeZone('UTC')); // then convert it to IST by $time->setTimezone(new DateTimeZone('IST')); echo $dt->format('r'); ?>