Tag Archives: PHP

PHP: Print amount or number in words

Its been real long since I updated this space. And instead of adding something for the heck of it, I thought of posting something really useful. This is a piece of PHP code that returns an amount/number in words. This is in English, but you can easily translate it to your own. Hope this helps!

This reminds me of Semester 1 assignment given by Shalini Puri ma’am to determine the optimal number of currency coins & notes required to put together a specified amount. Good old days!

Something for your empty home

Here are few lines of code that I have repeatedly found useful, especially when moving home between different web hosts.

Print the complete address of the page from where it is hosted:

<?php
$pageURL = $_SERVER[‘HTTPS’] == ‘on’ ? ‘https://’ : ‘http://’;
$pageURL .= $_SERVER[‘SERVER_PORT’] != ’80’ ? $_SERVER[“SERVER_NAME”].”:”.$_SERVER[“SERVER_PORT”].$_SERVER[“REQUEST_URI”] : $_SERVER[‘SERVER_NAME’] . $_SERVER[‘REQUEST_URI’];
echo $pageURL;
?>

Everyone knows about phpInfo – a dump of all the PHP settings:

<?php phpinfo(); ?>

When using a shared host that allows overriding your PHP ini file, it is worth while knowing the path from where the file is loaded:

<?php var_dump( get_cfg_var(‘cfg_file_path’) ); ?>

Converting CSV/Excel data to Doctrine YAML fixtures

I had done some research on this topic and found that some script was available in Python. With no knowledge of Python execution, I sought help from stackoverflow & got the answer there pointed to the same Python script 🙁 I decided I had to do something on my own! Ensuring the right no of spaces in the YAML could be a real pain – I haven’t found the error messages to be very friendly.

My challenge was to be able to generate a YAML for a table/schema using the nested-set behaviour in Doctrine. Instead of losing my mind on devising a human-readable format, I reverse engineered. I checked the resulting schema in the database and used that as the base for my CSV. Following this I wrote a simple macro that will output in the required format. This has evolved over a week or so, and has been thoroughly tested. I am sharing this file with 2 examples: one for the JobeetJob schema & other from the Hierarchical Data page on Doctrine.

Let me know if this helps! Vote for the answer on StackOverflow.

To start using:

  1. Download the ZIP file CSV/Excel to YAML Generator v2 & unzip it.
  2. Change the model name Continue reading Converting CSV/Excel data to Doctrine YAML fixtures

Setting up my Press, Part 2: Choosing the right property

This trilogy titled ‘Setting up my press’, will definitely not serve as a tutorial, is only an account of my decade long experience with web hosts & getting along with WordPress. In Part 1, I discussed my build-or-use decision and WordPress PoC. In this part, I will put my decade long experience with web hosting to use to help buy web-estate wisely. Do stick around for Part 3 on installation tips & must-have plug-ins. Continue reading Setting up my Press, Part 2: Choosing the right property