How-to articles, tricks, and solutions about PHP

Split text string into $first and $last name in php

In PHP, you can use the explode() function to split a string into an array, where each element of the array is a substring that was separated by a specified delimiter.

SQLSTATE[42S22]: Column not found: 1054 Unknown column

It looks like you are encountering an error with the message "SQLSTATE[42S22]: Column not found: 1054 Unknown column".

SQLSTATE[HY000] [1698] Access denied for user 'root'@'localhost'

This error message typically indicates that the MySQL server is unable to authenticate the user 'root'@'localhost' with the provided password.

Strict Standards: Only variables should be assigned by reference PHP 5.4

This error message is indicating that a value is being assigned to a variable by reference, which is not allowed in PHP version 5.4 or later

String comparison using '==' or '===' vs. 'strcmp()'

In PHP, you can use either the == or === operator to compare two strings.

submit a form in a new tab

To open a form submission in a new tab, you can use the target attribute of the form element and set it to _blank.

Submit html table data with via form (post)

Here is an example of how to submit an HTML table data via a form (using the POST method) using PHP:

Switch in Laravel 5 - Blade

In Laravel 5, the Blade templating engine provides a "switch" statement that allows you to compare a variable to multiple values and execute different code for each match.

Symfony error The class XXX was not found in the chain configured namespaces XXX

This error message is indicating that the Symfony framework is unable to find a specific class within the namespaces that have been configured.

Symfony2: Redirecting to last route and flash a message?

In Symfony2, you can redirect to the last route using the redirect function and passing in the referer option:

syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

This error message is typically encountered when there is a problem with the syntax of a string in PHP.

TCPDF ERROR: [Image] Unable to get image

This error message is typically associated with the TCPDF library, which is a PHP class for generating PDF files.

TCPDF ERROR: Some data has already been output, can't send PDF file

This error message is typically encountered when using the TCPDF library to generate a PDF file, and it indicates that some data (such as HTML or text) has already been sent to the browser before the PDF file is generated and sent.

TCPDF Save file to folder?

To save a file generated by TCPDF to a specific folder, you can use the TCPDF "Output" function.

Tell Composer to use Different PHP Version

To use a specific version of PHP with Composer, you can specify the version you want to use in the config section of your composer.json file.

The CSRF token is invalid. Please try to resubmit the form

This error message is typically related to a security feature called "Cross-Site Request Forgery" (CSRF) protection.

The Mix manifest does not exist when it does exist

This error message typically indicates that the Laravel Mix build process is unable to find the mix-manifest.json file that it generates when you run the npm run dev or npm run production command.

The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

It is true that the MySQL extension is deprecated, and it is recommended to use either MySQLi or PDO instead.

The openssl extension is required for SSL/TLS protection

The openssl extension in PHP is required to provide SSL/TLS support.

Troubleshooting "The use statement with non-compound name"

The error "The use statement with non-compound name" usually indicates that you are trying to use a namespace in a use statement, but you did not provide a compound name.

Truncate a string to first n characters of a string and add three dots if any characters are removed

To truncate a string to the first n characters and add three dots if any characters are removed in PHP, you can use the following function.

Truncate string in Laravel blade templates

To truncate a string in a Laravel blade template, you can use the str_limit function.

Try/Catch block in PHP not catching Exception

There could be several reasons why a try/catch block in PHP is not catching an exception.

Trying to get Laravel 5 email to work

To get Laravel 5's email functionality to work, you will need to configure your SMTP settings in the .env file, located in the root directory of your Laravel project.