Tag Archives: PHP

How to deploy a Laravel app

As I promised in the most recent Laravel post, today we are going to talk about how to deploy a Laravel app to a production environment.  At the time that I write this, the most recent version of Laravel is 9.x but when you read this, there is a good chance that 10.x or 11.x will be available.  Starting with the release of Laravel 8, they transitioned to yearly releases.  Prior to that they were releasing major versions every 6 months.  Version 9 was released on February 8, 2022, it is scheduled to receive bug fixes until August 8, 2023, and it is scheduled to receive security fixes until February 8, 2024.  Laravel used to have an LTS (long-term support) version (similar to what Ubuntu does) but the LTS had 3 years of support and every version after version 8 has two years of support, so I’m guessing that it is what killed the LTS.  For this post, we are going to focus on version 9. Continue reading How to deploy a Laravel app

Learning Laravel: Composer and The Laravel Installer

I spent years writing Laravel code at UWM but you might have noticed that I almost never wrote anything on this blog about it.  I am hoping to address that here and now.  If you don’t already know, Laravel is a free, open-source PHP web framework, intended for the development of web applications following the model–view–controller architectural pattern. Continue reading Learning Laravel: Composer and The Laravel Installer

PHP function of the day: sha1()

For day 21 of 21 in the “PHP Function of the day” series, I’m going to look at sha1().  This is similar to the md5() function that we looked at on day 12.  I’ll start by saying that sha1 isn’t great and should not be used for storing password hashes.

Let’s take a look.

<?php

$stringToHash = “Joe was here”;

$otherStringToHash = “Joe is here”;

echo sha1($stringToHash).”<br />”;

echo sha1($otherStringToHash).”<br />”;

?>

 

See the output

 

As you can see, this function just outputs a sha1 hash of the input. 🙂

PHP function of the day: array_rand()

For day 20 of 21 in the “PHP Function of the day” series, I’m going to look at array_rand().  The function takes a required array and an optional number of random keys to return.  It returns a random key (not the value).

Let’s take a look.

<?php

$names = array(“Joe”,”Jim”,”Sarah”,”Jill”);

$numbers = array(1,2,3,4,5,6,7,8,9);

$names_rand_keys = array_rand($names,3);

$numbers_rand_keys = array_rand($numbers);

echo $names[$names_rand_keys[0]].”<br />”;

echo $names[$names_rand_keys[1]].”<br />”;

echo $names[$names_rand_keys[2]].”<br />”;

print_r($numbers[$numbers_rand_keys]);

?>

 

See the output

 

As you can see, you can also probably just use rand() and just limit it to the size of the array.

PHP function of the day: date_diff()

For day 19 of 21 in the “PHP Function of the day” series, I’m going to look at date_diff().

Let’s take a look.

<?php

$shoppingDay=date_create(“2020-05-28”);

$payDay=date_create(“2020-06-01”);

$difference = date_diff($shoppingDay,$payDay);

print_r($difference);

echo “<br /><br />”.$difference->format(“%R%a days”);

?>

 

See the output

 

As you an see, this calculates the difference between two dates (something that could be pretty useful).

PHP function of the day: srand()

For day 18 of 21 in the “PHP Function of the day” series, I’m going to look at srand(). The function lets you specify the seed for rand().  In modern versions of PHP, rand() is seeded automatically and there is no real reason to do this.  So, why the explanation?  YOLO? 🙂

Let’s take a look.

<?php

srand(mktime());

echo(rand());

?>

 

See the output

 

There are three more posts left in this series.  Starting next week, I’m going back to the cadence that I was using in April.  Later in the year, I might try this daily post thing again.  Have a question, comment, etc?  Feel free to drop a comment below.

PHP function of the day: print_r()

For day 17 of 21 in the “PHP Function of the day” series, I’m going to look at print_r(). We have already used print_r() on days 4, 5, and 11.

Let’s take a look.

<?php

$num = 123;

$str = “Joe”;

$arr = array(1, 2, 3);

print_r($num);

print_r($str);

print_r($arr);

?>

 

See the output

 

As you can see, the function just dumps the value to the page.  The reason why it was used in the array_diff(), array(), and gettimeofday() posts is because (unlike echo()) it can handle more than just strings and numeric values.

PHP function of the day: printf()

For day 16 of 21 in the “PHP Function of the day” series, I’m going to look at printf(). This one is pretty interesting.  It allows you to define a format and a series of arguments.  The “%[something]” in the format string is used to define both where the argument’s value is output and the expected format.  In the format string below, “%s” is a string, “%u” is an unsigned decimal number, and “%%” is simply a percentage symbol.

Let’s take a look.

<?php

$name = “Joe”;

$food = “Chicken”;

$percentHungry = 72;

printf(“My name is %s and I am %u%% hungry for %s.”,$name,$percentHungry,$food);

?>

 

See the output

 

There are a variety of possible format values.  It is worth looking up all of the options.

PHP function of the day: array_flip()

For day 15 of 21 in the “PHP Function of the day” series, I’m going to look at array_flip(). As you might guess, this function “flips” the array so that the key is the value and the value is the key.

Let’s take a look.

<?php

$joe = array(“fname”=>”Joe”,”lname”=>”Steinbring”,”website”=>”jws.dev”);

print_r($joe);

echo(“<br />”);

print_r(array_flip($joe));

echo(“<br /><br />”);

$foods = array(“Beans”, “Apples”, “Wine”, “Pizza”);

print_r($foods);

echo(“<br />”);

print_r(array_flip($foods));

?>

 

See the output

 

You might have noticed that I missed this past Thursday and Friday’s posts.  I took an extended weekend, so I am posting them on Monday.  There should be just one week of these PHP function posts left.