In this article, I would explain how we can add a new set of categories to an already existing node by using existing taxonomy terms as reference id in Drupal 6. In order to achieve this, the following functions can be used: taxonomy_get_parents_all(), taxonomy_get_term(), node_save().
PHP
I was faced with a requirement to convert number to words/string in Indian naming system with lakhs and crores. I had to generate the amount in words for printing it out on a bill. The total amount, provided to the customer, needed to be converted to string. For example, if 1345673 was to be converted to Thirteen lakh Forty Five Thousand Six Hundred and Seventy Three, these functions will have to be followed.
Comma separated values, commonly referred to as CSV is one of the most popular methods for transferring data between systems. Creating code to export data to CSV is extremely useful in many applications. If you want to know how to create CSV files using PHP then read on.
cURL is a very powerfull system which allows us to transfer data across a wide variety of protocols. cURL is commonly used to send data across websites which includes API interaction. Using a cURL request, we can do the basic HTTP request, the more complex FTP upload or interaction with an authentication enclosed HTTPS site. In this section we will go through how cURL is intialized, how to send cURL request and close the requests.
By default, all HTTP requests made out by cURL are GET requests. It simply fetches the URL and doesn't submit any POST variables. However, if we need to fetch and retrieve URL by the POST method with cURL, you will need the snippet below:
Are you looking for a way manipulate dom elements using javascript based on some values from PHP, then this article is for you. We had recently worked in a Drupal 6 site having the same scenario. Our requirement was to enable some checkboxes using javascript based on the values of some variables available in the backend, This was accomplished using Drupal.settings
In a Wordpress we can assign categories to each post and have listing of posts in each categories. Sometimes we need to list the contents of a particular category as the home page. In Wordpress we can make a static page as the home page under the settings tab, i.e. Settings » Reading settings. There you can make a static page as home page but not the contents in a category.
My requirement was to detect the mobile devices from the drupal backend and redirect the user to the assigned URL. For this we needed to identify whether the user was accessing the site from a mobile device. For this we had to check the user agent string and compare that with the most common mobile devices. Then depending upon the condition we redirect the user to the corresponding URL.
I had a requirement where I had to execute shell command from PHP. The requirement was that I had to find details of a domain using commands like whois and then store this information into files in a folder. The only input parameter for the process was the name of the domain which was passed on from the Drupal site. The PHP function (shell_exec) was designed to do things like this.
One of the errors we come across in a Drupal 6 installation is "htmlspecialchars() expects parameter 1 to be string, array given in /includes/bootstrap.inc on line 860". This is an issue with the Internationalization and Taxonomy translation modules. This issue can be fixed by adding a line in the bootstrap.inc file. If you want to know how to solve the warning, continue reading.
The function of the script is to rename a specific-directory present under all sub-directories of a specified parent folder. Consider, you have a particular folder under all sub-directories of a folder and you want to rename all of those occurrences. Doing it manually would take much time. Here is a script to make it easy for you.
The script takes the following inputs:
'path' is the absolute path of the parent folder, and
'foldername.txt' is a text file which contains the names of the subdirectories under each of which the specific directory has to be renamed.
A number of Drupal users have encountered a White screen page accompanied by a "PHP error: Call to a member function value() on a non-object" error message when accessing the Checkout Review page of the Drupal Commerce module. If you are facing the same situation with Drupal Commerce in your Drupal site then read on to find out the solution.
Many Drupal programmers, Drupal site admins and Drupal site users have encountered errors similar to "User warning: Illegal mix of collations (PDOException: SQLSTATE[HY000]: General error: 1267)" in their Drupal site. If you are facing the same situation in your Drupal site then read on to find out more.
Have you ever encountered a situation where you have to find a specific pattern in a string and had to replace it with a new pattern in PHP. You will often encounter such situations during web development or any type of programming. Read on to know how to find a specific pattern in a string and replace it with a new pattern using PHP.
We have been facing the error message "Fatal error: Class 'PDO' not found in includes/database/database.inc on line 184" in one of our Drupal sites. Googling up the error text had brought out a number of solutions which did not help to resolve the error in our case as there is no single cause of the error. However we managed to solve it using a different method. If you are facing the same scenario in your Drupal site and want to know how to solve fatal error with Class 'PDO' in Drupal sites the continue reading for the solution.
Many Drupal programmers, Drupal site admins and Drupal site users have encountered errors similar to "PHP Notice: unserialize() ... : Error at offset 6 of 10 bytes in ... \includes\bootstrap.inc on line 568" in their Drupal site. If you are facing the same situation in your Drupal site then read on to find out more.
You might have come across a situation where you need to set the title of the content as the filename for an uploaded image or where you might need to replace the spaces and special characters from the filename of an uploaded file. In such conditions you can use preg_replace. I will show you some example code where the output string will be nice and clean and can be used for setting file names.
We start thinking about global variables when we want something to be available just everywhere. One case is when we want a particular variable to be available to all modules in a site. In Drupal, global variables are usually defined in settings.php. With that, all modules can access that variable.
APC or Alternative PHP Cache (APC) is a free and open opcode cache for PHP. APC allows for caching of opcode generated during PHP script parsing and execution by the Zend engine. If you are using APC 3.1.9 and you are using the default configuration you might run into the error where most PHP requests will return a warning message "PHP Warning: Unknown: Unable to allocate memory for pool. in Unknown on line 0"
Sometimes we get requests to update Drupal sites and get it done in less than 5 hours. If we take the Drupal update through the full fail-safe set of steps for Drupal updates we will never be able to complete updates in less than 5 hours on a site we don't maintain. For such sites when the cost of the site going down may not be too high for the site owner it might not be too big an issue if the update is run on a hit or miss approach. We normally do not recommend such an approach but this should work on most small sites without any issues.