I’m passing values into a PHP page through the URL and using them in queries with MySQLi. The problem is that an empty string gets converted to zero for an integer column, when in fact it needs to be NULL. How do I get NULL into an integer column with PHP/MySQLi, from a param passed in the URL? Update: …
Tag: php
How to make “LIKE” query work in MongoDB?
I have a list of street names and I want to select all that start with “Al”. In my MySQL I would do something like How about MongoDB using PHP? Answer Use a regular expression: or: http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-RegularExpressions Turning this into PHP:
Different session ID every time session_start is executed
I have the following source code session1.php session2.php when I access session1.php then access session2.php, I get a different ouput. Why is this doing it? Answer The browser is not sending the session cookie back to the server. This can have two reasons. The browser is configured not to send cookies to th…
PHP: Adding months to a date, while not exceeding the last day of the month
Looking to create a function that will do this in PHP. I need to add a number of months to a date, but not exceed the last day of the month in doing so. For example: Add 1 month to January (1-…
How to convert PNG to 8-bit PNG using PHP GD library
I want to write a routine which takes PNG image path as parameter and convert that image into 8-bit PNG image. I need to use PHP GD library for this. Answer To convert any PNG image to 8-bit PNG use this function, I’ve just created function convertPNGto8bitPNG () Parameters $sourcePath – Path to s…
Permutations of an array of arrays of strings
I simply cannot wrap my head around how to solve this problem and after a thorough search on Google with no results, I turn to you with hopes of a solution. Given the sample array below: (Note: This is merely a sample; the actual real life situation might have less/more groups and/or elements per group) How w…
Is it better call a function every time or store that value in a new variable?
I use often the function sizeof($var) on my web application, and I’d like to know if is better (in resources term) store this value in a new variable and use this one, or if it’s better call/use every time that function; or maybe is indifferent 🙂 Answer TLDR: it’s better to set a variable, c…
vsprintf or sprintf with named arguments, or simple template parsing in PHP
I’m searching for a way to use named arguments for sprintf or printf. Example: or via vsprintf and an associative array. I have found some coding examples here http://php.net/manual/de/function.sprintf.php and here http://php.net/manual/de/function.vsprintf.php where people wrote their own solutions. Bu…
PHP + tcpdf: How can I reduce file size when generate with local language
Now my web app using class tcpdf to convert all pdf file (in English) and file size is around 500K. But when I change the font style to my local language (Free-serif) then file size is over 1M (…
“Function split() is deprecated” in PHP?
Deprecated: Function split() is deprecated in C:wampwwwRSS.php on line 27 Why this error happen ? Answer http://php.net/manual/en/function.split.php From the manual Warning This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged Note: As of PHP 5.3.0, the regex extensi…