09/05/23 | PHP | Check if session_start() is already running | By Raymond Hernandez |
Avoid creating duplicate PHP sessions. Paste on every top of PHP scripts. | |||
|
|||
08/30/23 | PHP | Attributes | By Raymond Hernandez |
Attributes provide a way to add metadata to classes, methods, properties, and more. They can be retrieved at runtime using the Reflection API. | |||
|
|||
08/30/23 | PHP | JSON for Simple Serialization | By Raymond Hernandez |
Instead of using PHP's serialize() and unserialize(), using JSON is more portable across different systems and languages. | |||
|
|||
08/30/23 | PHP | Late Static Bindings | By Raymond Hernandez |
It's a way to reference the called class in a context of static inheritance. self:: refers to the class in which it is called, while static:: refers to the class that was originally called. | |||
|
|||
08/30/23 | PHP | Output Buffering | By Raymond Hernandez |
This allows you to capture all output (like echo) in a buffer. This can be useful if you want to manipulate the output before sending it to the browser. | |||
|
|||
08/30/23 | PHP | List() & Foreach | By Raymond Hernandez |
With the list() function, you can assign multiple values in an array to multiple variables in one go. | |||
|
|||
08/30/23 | PHP | Variable-length Argument Lists | By Raymond Hernandez |
Functions can accept a variable number of arguments without explicitly declaring the number of parameters. | |||
|
|||
08/30/23 | PHP | Group Use Declarations | By Raymond Hernandez |
This is a concise way to import multiple classes, functions, or constants from the same namespace. | |||
|
|||
08/30/23 | PHP | Generators | By Raymond Hernandez |
Generators provide an easy way to create iterators without implementing the Iterator interface. They yield values one at a time using the yield keyword and save memory when dealing with large data sets. | |||
|
|||
08/30/23 | PHP | Spaceship Operator | By Raymond Hernandez |
It returns -1, 0, or 1 when $a is respectively less than, equal to, or greater than $b. It's handy for sorting functions. | |||
|
|||
08/30/23 | PHP | NULL Coalesce Operator | By Raymond Hernandez |
This operator is a shorthand for checking if a variable exists and has a non-null value. If it does, it returns its value; otherwise, it returns the value on the right side. | |||
|
|||
08/30/23 | PHP | Array Destructuring | By Raymond Hernandez |
Array destructuring allows you to unpack elements from arrays directly into named variables. This can be especially useful in loops or when working with list-like structures. | |||
|
|||
08/30/23 | PHP | Anonymous Classes | By Raymond Hernandez |
Disposable Class so you don't have to assign a Class name. | |||
|
|||
08/19/23 | PHP | JavaScript Alert Box and Forward Header Wrapped in PHP | By Raymond Hernandez |
An alert box that redirects to a different URL and displays a message or error notice if needed. | |||
|
|||
01/30/23 | PHP | Translate English Months to Tagalog | By Raymond Hernandez |
For a project I'm working on since it's parsing in Tagalog but the Date() in PHP only works in English. | |||
|
|||
01/15/23 | PHP | Export your SQL Table as a CSV File | By Raymond Hernandez |
If a specific column needs to be modified, make sure to do it before fputcsv(). The headers are used to prepare the file for download, by specifying the type of file, name, time for expiry and whether to cache the file or not. The readfile function will read the contents of the file and output it to the browser, so that the browser can download it. | |||
|
|||
01/13/23 | PHP | Get GPS Coordinates from an Address (using cURL) | By Raymond Hernandez |
This version of the function uses cURL library instead of file_get_contents to send the request to the google api, cURL is more efficient and flexible than file_get_contents and also it provide more options like handling redirects, cookies and more. | |||
|
|||
01/12/23 | PHP | Display PHP Errors for Debugging | By Raymond Hernandez |
It's hard to track PHP errors, well at least for me anyway so I add this on every page I need to debug. | |||
|
|||
01/11/23 | HTML | Paginate Your Site | By Raymond Hernandez |
This is the code I used for the Territories page of Service Records. The code below must be pasted on each page that needs pagination...
|
|||
|
|||
01/11/23 | PHP | Get GPS Coordinates from an Address | By Raymond Hernandez |
Must use your own Google Maps API to query addresses. | |||
|
|||
01/11/23 | PHP | Paginate Your WordPress Site | By Raymond Hernandez |
Effective pagination improves user experience by enabling them to navigate through your website using intuitive links such as 'previous' and 'next' rather than searching manually. Our WordPress code snippet can assist in implementing this feature. | |||
|
|||
01/10/23 | PHP | Disable Search in WP | By Raymond Hernandez |
Disable Search in WordPress
This code hooks into the template_redirect action in WordPress, which is run before the template for a specific page is selected. The is_search() function checks if the current page being viewed is a search results page. If it is, the wp_redirect() function redirects the user to the homepage of your website, and the exit command stops the rest of the code from running. This should disable the search feature on your website. It will redirect all the requests made to search page to home page. |
|||
|
|||
01/10/23 | PHP | Allows Upload Images to WP | By Raymond Hernandez |
Allows contributors to upload images to WordPress. Paste to functions.php. | |||
|
|||
01/10/23 | HTML | Dynamic Footer | By Raymond Hernandez |
Footer for all my sites. Year is dynamic with the current year. | |||
|
|||
01/10/23 | PHP | Display All Rows - WHILE Loop | By Raymond Hernandez |
This is the WHILE loop I use for all my sites to display all row values from a database. | |||
|
|||