Monthly Archives: May 2012

Run Update SQL query with if clause

Description: Running an SQL script that performs a update depending on some given conditions. Solution: SQL query can take if clauses in the shape of cases: UPDATE table SET name = case WHEN id = 1 then ‘John’ ELSE null … Continue reading

Posted in SQL | Tagged , | Leave a comment

Export HTML to PDF

Description: Export a HTML page to PDF in PhP Solution: The best solution is installing a 3rd party tool like wkhtmltopdf . The tool is easy to install on Windows, but a bit more tricky on a Linux machine. The … Continue reading

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

Add special characters to CSV export in PHP

Description: When exporting data to CSV, the special characters are not displayed, as the ending ; is treated as a new column. Solution: Check the encoding of the CSV file. Make sure this is utf-8. However, in some cases this … Continue reading

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

Parse CSV file in PHP and retrieve contents

Description: Retrieve CSV file contents in PHP. Solution: The parsing is done in 2 steps. First read the .csv file: $handle = fopen(“file.csv”, “r”); $csv = array(); while(($data = fgetcsv($handle)) !== FALSE) { // get the values from the csv … 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

Iterate Array contents in Smarty templates

Description: Iterate an Array passed as a variable in a Smarty template Solution: The equivalent of foreach() clause in PHP translates as section in Smarty templates, as following: {section name=arrayID loop=$theArray}     <input type=checkbox” name=”{$theArray[arrayID ]}” {/section} The code above … Continue reading

Posted in PhP | Tagged , | Leave a comment

Check regex

Description: Which are the best regular expression testing tools online? Solution: http://gskinner.com/RegExr/ – offers great support, samples, history and has a community of users behind it http://www.regextester.com/ – tester tool plus examples and constant updates http://regexpal.com/ – offers a bunch … Continue reading

Posted in PhP | Tagged , | Leave a comment