How-to articles, tricks, and solutions about PHP

RuntimeException: Unable to create the cache directory (/var/www/sonata/app/cache/dev)

This error message indicates that the system is unable to create a cache directory at the specified location.

Save image from url with curl PHP

To save an image from a URL using PHP and cURL, you can use the following function:

Save PHP array to MySQL?

To save a PHP array to a MySQL database, you can use the serialize() function to convert the array into a string, and then use an INSERT or UPDATE statement to save the string into a TEXT or LONGTEXT field in the database.

Saving file into a prespecified directory using FPDF

To save a file using FPDF, you can use the "Output" method.

search a php array for partial string match

You can use the array_filter() function in PHP to search through an array and return only the elements that contain a certain string.

search and replace value in PHP array

In PHP, you can use the array_map() function to search and replace values in an array.

Secure hash and salt for PHP passwords

To securely hash and salt passwords in PHP, you can use the password_hash function.

Select mySQL based only on month and year

To select data from a MySQL database based on the month and year, you can use the MONTH and YEAR functions in your SELECT statement.

Select records from today, this week, this month php mysql

To select records from today, you can use the following code:

selecting unique values from a column

To select unique values from a column in PHP, you can use the array_unique function.

Send email with a template using php

To send an email using PHP, you can use the "mail()" function.

Send html form data to sql database via php (using mysqli)

To send HTML form data to a SQL database using PHP, you will need to use the mysqli (MySQL Improved) extension in PHP.

Send value of submit button when form gets posted

In PHP, you can access the value of a submit button when a form is posted in the following way:

Sending multiple data parameters with jQuery AJAX

To send multiple data parameters with jQuery's $.ajax() function in PHP, you can use the data option and set it to an object with the data you want to send.

setcookie, Cannot modify header information - headers already sent

The error message "Cannot modify header information - headers already sent" typically occurs when a PHP script attempts to send a cookie or redirect the user's browser to a different page, but some output has already been sent to the browser.

Setting PHPMyAdmin Language

To set the language for PHPMyAdmin, you can do the following:

Setting POST variable without using form

To set the value of a POST variable in PHP, you can use the following code:

Setting public class variables

In PHP, you can set the value of a public class variable by using the assignment operator (=) after the variable name.

Setting up SSL on a local xampp/apache server

To set up SSL on a local XAMPP/Apache server, you will need to generate a self-signed certificate, configure the Apache server to use the certificate, and then access the server using https.

Short unique id in php

In PHP, you can use the function uniqid() to generate a short unique ID.

Simple DatePicker-like Calendar

A simple DatePicker-like calendar can be created using the PHP DateTime class and some basic HTML and CSS.

Simple example to post to a Facebook fan page via PHP?

Here is an example of how you can post to a Facebook fan page using the Facebook PHP SDK:

SimpleXml to string

To convert a SimpleXml object to a string in PHP, you can use the asXML() function.