Tag Archives: php

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

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

Recreate date and time from a timestamp in PHP

Description: Reconstruct readable date and time from an integer timestamp. Solution: We have to use the date() function of PHP. The function takes a string containing the structure of the desired outputted date and the timestamp which we will use: … Continue reading

Posted in PhP | Tagged , , | Leave a comment

Send emails with attachment in PHP

Description: How to send e-mails with attachments from a PHP script? Solution: The mail function of PHP supports also attachments. So, in creating the mail object we can add the attachment like this: $to = ‘myname@mail.com’; $subject = ‘Hello world … Continue reading

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

Get time difference in PHP with microtime()

Description: Detect how long a script, query or function takes to run in php. Solution: PHP offers the microtime() function, which returns the number of microseconds (a millionth of a second) that passed since 1st of January 1970, the PHP … Continue reading

Posted in PhP | Tagged , , , | 3 Comments

Create and download file without saving on server

Description: How to create a file on the server without saving it, just giving the user the possibility to open it or save it on the local machine? Solution: First, create the file contents as you would do normally. Then … Continue reading

Posted in PhP, Tools | Tagged , , | 4 Comments

Get timestamp from a date string in PHP

Description: Having a date string, return timestamp. Helpful when wanting to have the timestamp for a given date in known format. Solution: PHP has the function strtotime() that returns an integer timestamp for a given date string. int strtotime ( … Continue reading

Posted in PhP | Tagged | Leave a comment