Category: PHP
-
PHP caveats – int/float type conversion
The following code checks various scenarios in which inbuilt functions like intval, floatval, is_numeric, is_float and filter_var would result for several different types of values. Feel free to run in your local, leave comments if I can make the results more interesting with some more functions. https://gist.github.com/harshvardhanmalpani/8dd0222e4821d0e495532abe9007fef1 Output / Results
-
How to migrate Customers from Magento2 to WordPress?
Lets break it into 2 parts: a. Migrate Customer datab. Migrate Customer Passwords 1) Migrate Customer Data from Magento2 to WordPress This is rather easy to be honest, there are several plugins for importing data from CSV and then mapping the CSV fields. My recommended plugin is Customer/Order/Coupon CSV Import Suite by SkyVerge It basically…
-
How to batch edit multiple images to make square sized pictures with original image in center using php imagejpeg?
-
Sort keys of an array based on order of values in another array – PHP
-
How to filter and validate pincode in Indian woocommerce?
By default, Woocommerce only validates ZIP code of few countries only. Woocommerce stores in India, are thus invalidated in case of PINCODE inputs from customers. Here is how you can enable checking of pincode for India woocommerce: Put the following code in your custom function file or child theme functions.php Reference: https://github.com/woocommerce/woocommerce/blob/ef0f527b40dba539e982efff26211fa577a24cf9/includes/class-wc-validation.php#L44
-
Funny php bug due to hashing and is_numeric
So I was working on an automation project and was testing the api to upload entitites. I used get parameters to send data and wrote a wrapper on server to process that. I used hashes (part of hashes to be precise) to identify the requester instead of using real names. some name came up with…
-
How to reverse the ids in a mysql table column without breaking primary key constraint?
Let me explain the problem scenario: Let us assume we have a table with 4 columns in it out of which 1 is PRIMARY column and rest 3 contain some data. What we want to do is to reverse the primary key IDs for that data keeping the rest of data intact. It is like…
-
How to fix Undefined class constant ‘ARRAY_AS_PROPS’ Fatal Error?
I received this error “Fatal Error: Uncaught error in Undefined class constant ‘ARRAY_AS_PROPS’”This issue is not related to PHP if you have 7.0 and above, it is zend framework’s module zend-http wrapper which is affected if Apache module is not present File responsible: zendframework\zend-http\src\Header\Cookie.php:75 Solution Do check enabled modules for Apache, I found out that…
-
How to transpose an array in PHP with irregular subarray size?
Test Code Output
-
How to fix Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI error in SSH?
Put this in your bash profile and run source ~/.bashrc As Composer is now available via WHM you can use this to find it: This returned path “/opt/cpanel/composer/bin/composer” for me. If this returns nothing then disregard the rest of this answer, as Composer is not available to you at system level. You can now use php-cli to…