PHP

Playing With AI

Playing with AI and Learning to Keep It Simple, Silly

Yesterday I was playing with AI in the evening and I asked it to help me write a function that would detect whether an array item was a photo or a video. I told the AI, this is a photo array item, and this is a video array item. I want the photo array item to display the img src code and for the video item to be displayed with video src code. At first it failed to detect anything and gave me an error message. I decided to highlight the photo array item snippet and the video array snippet. It didn’t come back with an error but it did not display any img or video code. In the end I decided to say “here’s the img src tag. I want you to detect whether the file is mp4 or jpg. If it’s mp4 add the video player, and if it’s a photo load the image. I went from asking it to read the array to determine what to do, to “check the filetype and load the appropriate src type. That worked, and required very little code. Don’t Over-Engineer With AI The moral I came away with, after the trial and error I went through last night is that whilst AI is great at reading and understanding code, and giving us answers it can sometimes fail. I was making something far more complicated than it had to be and chatGPT got confused, as would a human trying to complicate something simple. PHP has a lot of functionality built into it. It has tools that allow it to read exif information, file types and more, and if you know about these tools, then you can come up with elegant solutions, rather than complicated ones.

From Instagram Archive to PHP Website

Three years ago I stopped using Instagram because I was tired of seeing influencers and adverts rather than by the people I chose to follow. The cherry on the cake, that pushed me to dump Instagram is when they changed the location of the Post button from the left corner to the top right and changed the default from photo to story.

For ten years or more I used instagram and shared photos, and I enjoyed capturing at least an image or two every single day. It’s because Instagram was bought by Facebook that I fell out of love with the site and decided not to use it anymore. The community had been lost, so what good was there in sticking around? 

Laravel and Context

There is value in studying Laravel and context. By this I mean that over a year ago I wanted to study Angular but after feeling lost in Javascript I decided to take a step back, to study JavaScript. I studied two or more courses over a period of months. I could have followed a single course and claimed that I knew and understood JavaScript but that would have been misleading.

Laravel and Chirper

Today I used Laravel to code a Twitter clone called Chirper via the tutorial you can find here. The tutorial took about two hours before I got the notifications section of the tutorial. The tutorial is easy to follow and with my contextual knowledge I was able to write most of the code with a minimum of errors. The tutorial follows the CRUD model, Create, read, update delete, and adds in notifications for good measure.

Learning About Laravel and PHP

Today I started to follow a course where someone turns a static html page into a Laravel blog. I experimented with home.blade and one or two other features and I got two pages to load, and the login to work, without more than that.

What makes today’s learning and experimenting interesting is that the time I spent creating PHP arrays for my website content is now easy to transfer to json files for use with dynamic websites. What this means is that content that was stuck on individual pages is now organised by website section. I am now free to do more.

Conservation and PHP

Today I have struggled with PHP. I struggled because I want to recreate the same table using loops with PHP as I did formatting with HTML. If I wasn’t up for a challenge I would let PHP loops format it according the default and I’d be done. In the end I did get the table to display as I wanted but not using for loops. I created a table page, laid it out using the data file I’ve been using for this section, and then using include to add that content where I wanted it to be on the page.

A Rainy Day Without Walking

Today the weather app said that it would start raining at 1500 so I didn’t go out for a walk. In the end the rain started at around 1630 or even later. I could have gone for a walk and I could have come back dry or almost dry.

For years I went for walks almost everyday, whatever the weather conditions. I grew tired of the habit. I have had this habit for five years or more, three of which have been during the pandemic.

A Shift to PHP

PHP has been around for decades but I learned of a way to experiment with it easily recently so that is why I am playing with it now. The main page is php as is my first “blog” although it was part of a column for the student newspaper, that I converted to an electronic format and published frequently.

I tried to keep Surfing the World Wide Waves looking as it had back in the day. The aim is to practice with PHP and get some things to become automatic. I include one php file with the data, and a second for the footer. I use a loop to populate each blog post.

PHP from the Command Line

Recently I learned that PHP has a built in server. You don’t need xampp or any of the other solutions. All you need is terminal open, have the current directory be the one with the PHP files you want to serve and type: “php -S localhost:8000”

This might sound obvious to some but it took years for me to come across this. When you have to install xampp or other solutions you need to dedicate HD space, run the servers and more.

Learning To Code By Building CMSs

It’s easy to use Facebook or other CMS every day without thinking about how the code works. This summer I have coded two CMS using Linkedin Learning. One of these CMS was running with PHP and MySQL and the other was running with Ruby On Rails and MySQL.

The PHP CMS

In the process I learned how to install MySQL, how to get MySQL and PHP to talk to each other. How to organise files between private and public folders on a web server and more. Getting MySQL to talk with the web server was a challenge that took a few days to get right.