Category Archives: PhP

Run PHP Compatibility checks for upgrading version

Description: In order to bring the PHP version up to date, we need to run compatibility test on our projects. Solution: The CodeSniffer tool that can be installed on each system gives us the most precise results. Follow the guide … Continue reading

Posted in Best practices, Linux, PhP | Tagged , , , , , | Leave a comment

Requirements for sending e-mails from PHP

Description: We need to send e-mails directly from a PHP script. Solution: First, in php.ini the smtp port should be set to 25, but this is usually by default. To locate your php.ini file in the server configuration you can use … Continue reading

Posted in Linux, PhP, Wordpress | Tagged , , , , , , | Leave a comment

substr() cuts in the middle of & symbol

Description: In “Read more” segments, you often need to cut the text to a length and add ‘…’ at the end. This can be a bit tricky when the limit falls on a special character. Solution: We can use mb_substr() … Continue reading

Posted in Best practices, PhP | Tagged , , , , | Leave a comment

Reversing an Array in PhP

Description: Having an array, how to easily do to reverse the order of the elements. Solution: PhP offers an out-of-the box solution to this issue. It is the function array_reverse() which inverts the order of the array elements. A point to take … Continue reading

Posted in PhP | Tagged , | Leave a comment

Add line break in PDF generated from HTML without fix width

Description: By creating a PDF from HTML if you use tables and you want the table cells to flow easily not depending on the width of a specific cell, a long text is not broken into multiple lines, but the … Continue reading

Posted in Best practices, PhP | Tagged , , , , , | Leave a comment

Format number with decimals without rounding

Description: Trying to get a precise number of decimal in a number results most of the times in a rounding of the number. Both round() and number_format() functions of PhP round the output result. Solution: The solution to this issue is to … Continue reading

Posted in Best practices, PhP | Tagged , , , | 2 Comments

301 and 302 redirect, differences and implementation

Description: Is there any difference between 301 and 301 redirects ? Solution: Practically, there is limited difference between the two. To be precise, 301 redirect signals a permanent move of the page, while 302 reffers to a temporary move. This … Continue reading

Posted in Best practices, PhP, Script, Tools | Tagged , , , | Leave a comment

Convert StdClass objects to SOAP compliant objects

Description: Having an obtained StdClass Object, we require to change it into a SOAP structure object or Array compliant. Solution: Converting a StdClass Object with PhP basically means iterating the object and populating the public properties with elements from the … Continue reading

Posted in Best practices, PhP | Tagged , , , , | Leave a comment

Get current and past month with Zend Date

Description: Return current and previous months in Zend Framework, considering passing into a new year as well. Solution: Zend Framework, through Zend_Date() offers a quick solution for this problem. With the get() function we can return any part of the current date, and with … Continue reading

Posted in PhP, Tools, Zend Framework | Tagged , | 1 Comment

Send e-mail with attachments in Zend Framework

Description: Send an e-mail containing attachments with Zend Framework. Solution: Zend offers an easier solution for sending e-mail with attachements than plain PhP.  Basically the object has to be instantiated and then just configuring the parameters. Example: $email_body = “<div>Body … Continue reading

Posted in PhP, Tools | Tagged , , | Leave a comment