Home » Posts tagged with "php"

I have an array with many values and I need to do a search to find all the values that match a pattern. We have functions like in_array & array_search in PHP, but these functions basically try to match the exact needle value in the array. I need to use my Regular Expression Pattern and find all the array values that match the regex pattern. The...
In this tutorial, learn about the get_browser() PHP function and its configuration. We’ll learn how to use Gary Keith’s browser information database (browscap.ini) with the PHP browscap directive. I wanted one of my web applications to have a different appearance on mobile phones and devices. I didn’t really want to set up an entirely...
Often we search for records in a database table for fetching records that were created or modified on a particular date or between two dates. We match against a date field and add multiple conditions to find records with a date field value ranging between two dates. It would look something like this: Select * from tables where CREATE_TIME >= "2007-03-14...
When we need to swap the values of two variables, we use a third variable temporarily to hold the data between swapping.  Something like this: <?php $tmp = $a; $a = $b; $b = $tmp; ?> Here is another way without using a temp or a third variable. <?php list($b, $a) = array($a, $b); ?> And if you want to make it a function: <?php function...
The Auth Component in CakePHP redirects the user to the log-in page when a user tries to access any protected pages in the application. The default log-in page is set by defining the loginAction variable in the beforeFilter function in your UsersController or AppController. But if you have used plug-ins in your application, and if a user tries to access...
A very basic tutorial. For the beginners who want to pass array values from PHP to Javascript for them to be accessible in the client side JS as an array. It’s really easy to pass PHP array to Javascript. The below code passes a string array in PHP to Javascript. <?php $arr = array("a","b","c"); ?> <script> var...
Sometimes, or very rarely we might need to access a model in AppController (Application Controller). This could be for fetching values from a table and make it available for all the controllers in the application (AppController is inherited by all the other controllers). Also, often we need to access models that are not associated with a controller. I...
Filed in: CakePHP, PHP/MySQL
Developers normally use functions that use Regular Expression to convert under_scored strings in to CamelCased strings. Usage of Regular Expression is quite heavy. We can use a simple yet powerful method to convert these strings to CamelCase without using RegEx in PHP. Here is the method: echo join(””, array_map(“ucwords”, explode(‘_’,...
PHP Encountered Access Violation at [some random memory address] Many of the guys who asked me about this problem faced it when trying to run PHPMyAdmin or other applications which access database, after setting up a local PHP environment on their machine under IIS. Try these fixes. Add your PHP path (the location of PHP files in your machine) to the...
Filed in: PHP/MySQL
Often, we come across situations where we need to INSERT multiple rows in to a database table from an Array, File or even from another Database Table. I am explaining various methods for inserting multiple rows using a single query using MySQL and PHP. MySQL documentation says you can use the following methods to speed up inserts: If you are inserting...

Page optimized by WP Minify WordPress Plugin