PHP function of the day: date()

For day 14 of 21 in the “PHP Function of the day” series, I’m going to look at date(). The function takes a required format and an optional timestamp and outputs a formatted date. Let’s take a look. <?php echo “This is the “.date(“d”).”th day of the month.”.”<br />”; echo “This is the “.date(“m”).”th month of the …

Continue reading "PHP function of the day: date()"

PHP function of the day: rand()

For day 13 of 21 in the “PHP Function of the day” series, I’m going to look at rand(). This function generates a random integer.  You can feed it a minimum value and a maximum value or let it generate a value without the limits. Let’s take a look. <?php echo(rand().'<br />’); echo(rand().'<br />’); echo(rand(0,9)); ?>   …

Continue reading "PHP function of the day: rand()"

PHP function of the day: array_diff()

For day 11 of 21 in the “PHP Function of the day” series, I’m going to look at array_diff(). It gets the difference between an array and one or more other arrays. Let’s take a look. <?php $person1 = array(“fname”=>”Joe”,”lname”=>”Smith”); $person2 = array(“fname”=>”Jane”,”lname”=>”Smith”); $differences = array_diff($person1, $person2); print_r($differences); $person3 = array(“fname”=>”Stan”,”lname”=>”Smith”); $differences = array_diff($person1, $person2, $person3); print_r($differences); …

Continue reading "PHP function of the day: array_diff()"

PHP function of the day: min()

For day 9 of 21 in the “PHP Function of the day” series, I’m going to look at min(). This function takes values and returns the smallest value from what you provided. Let’s take a look. <?php echo(min(-1,0,1,2,3).'<br />’); echo(min(array(-1,0,1,2,3)).'<br />’); echo(min(array(‘a’,’b’,’c’,’d’))); ?>   See the output   As you can see, this is a lot like …

Continue reading "PHP function of the day: min()"

PHP function of the day: html_entity_decode()

For day 8 of 21 in the “PHP Function of the day” series, I’m going to look at html_entity_decode().  It takes HTML entities and converts them to HTML. Let’s take a look. <?php $html = ‘<h1>Hello!</h1><p>Joe\’s website is at: <a href=”https://jws.dev”>jws.dev</a></p>’; $encoded = htmlentities($html); echo $encoded.'<br />’; echo html_entity_decode($encoded); ?>   See the output   As you …

Continue reading "PHP function of the day: html_entity_decode()"

PHP function of the day: htmlentities()

For day 7 of 21 in the “PHP Function of the day” series, I’m going to look at htmlentities().  It takes HTML as an input and converts it to HTML entities. Let’s take a look. <?php $html = ‘<h1>Hello!</h1><p>Joe\’s website is at: <a href=”https://jws.dev”>jws.dev</a></p>’; echo ‘<br />’; echo $html; echo ‘<br />’; echo htmlentities($html); ?>   See …

Continue reading "PHP function of the day: htmlentities()"

PHP function of the day: json_decode()

For day 6 of 21 in the “PHP Function of the day” series, I’m going to look at json_decode().  You might remember json_encode() from last week.  Where json_encode() encodes data as JSON, json_decode() decodes JSON data. Let’s take a look. <?php $data = ‘{“First_Name”:”Joe”,”Last_Name”:”Steinbring”,”Website”:”jws.dev”}’; var_dump($data); echo(‘<br />’); var_dump(json_decode($data)); echo(‘<br />’); var_dump(json_decode($data, true)); ?>   See the output …

Continue reading "PHP function of the day: json_decode()"

PHP function of the day: array()

For day 5 of 21 in the “PHP Function of the day” series, I’m going to look at array().  Array() is what you use to create an array in PHP. Let’s take a look. <?php $array = array(1, 2, 3, 4); print_r($array); echo(“<br />”); $array = array(“Joe”, “Paul”, “Lisa”); print_r($array); echo(“<br />”); $array = array(“Name”=>”Joe”,”Address”=>”123 N Main …

Continue reading "PHP function of the day: array()"