How do I get PHP errors to display?

This always works for me: ini_set(‘display_errors’, ‘1’); ini_set(‘display_startup_errors’, ‘1’); error_reporting(E_ALL); However, this doesn’t make PHP to show parse errors – the only way to show those errors is to modify your php.ini with this line: display_errors = on (if you don’t have access to php.ini, then putting this line in .htaccess might work too): php_flag … Read more

When should I use ‘self’ over ‘$this’?

Short Answer Use $this to refer to the current object. Use self to refer to the current class. In other words, use $this->member for non-static members, use self::$member for static members. Full Answer Here is an example of correct usage of $this and self for non-static and static member variables: <?php class X { private … Read more

How does PHP ‘foreach’ actually work?

foreach supports iteration over three different kinds of values: Arrays Normal objects Traversable objects In the following, I will try to explain precisely how iteration works in different cases. By far the simplest case is Traversable objects, as for these foreach is essentially only syntax sugar for code along these lines: foreach ($it as $k … Read more

How do I check if a string contains a specific word?

Now with PHP 8 you can do this using str_contains: if (str_contains(‘How are you’, ‘are’)) { echo ‘true’; } RFC Before PHP 8 You can use the strpos() function which is used to find the occurrence of one string inside another one: $a=”How are you?”; if (strpos($a, ‘are’) !== false) { echo ‘true’; } Note … Read more

How do I get a YouTube video thumbnail from the YouTube API?

Each YouTube video has four generated images. They are predictably formatted as follows: https://img.youtube.com/vi/<insert-youtube-video-id-here>/0.jpg https://img.youtube.com/vi/<insert-youtube-video-id-here>/1.jpg https://img.youtube.com/vi/<insert-youtube-video-id-here>/2.jpg https://img.youtube.com/vi/<insert-youtube-video-id-here>/3.jpg The first one in the list is a full size image and others are thumbnail images. The default thumbnail image (i.e., one of 1.jpg, 2.jpg, 3.jpg) is: https://img.youtube.com/vi/<insert-youtube-video-id-here>/default.jpg For the high quality version of the thumbnail use a … Read more

Deleting an element from an array in PHP

There are different ways to delete an array element, where some are more useful for some specific tasks than others. Deleting a single array element If you want to delete just one array element you can use unset() or alternatively \array_splice(). If you know the value and don’t know the key to delete the element … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)