PHP

PHP Bijoy to Unicode Converter

In our latest project at PROGmaatic, we needed a converter to convert lots of information written in Bangla. Unfortunately  everything was in Bijoy (SutonnyMJ) font. But our requirement was Unicode formatted data and language preference was PHP.

 

I thought, no big deal. There should have been lots of converters available, and most of them might be in PHP. After hours of searching (Yes I don’t like coding when I can find something free :D).

Well, I haven’t found a single script which would do what I needed. Two of the following did help me to understand how to develop the converter:

So finally I end up coding one myself. Fork it from my Github account.

In the coding process I have learnt two valuable lessons 🙂

1. javascript string method ‘substring‘ is not equivalent to PHP’s string function ‘substr‘ [I spent only 5 hours for this mistake!!!]

2. Nothing is better than step-by-step Debugging!

 

Future modifications:

1. Make mbstring independent. (I actually figured out the way, but right now I don’t need it since I have mbstring support :))

2. Make memory efficient.

 

Check the code and let me know if you find a better way, find a bug or need some modification. I will be happy to make the changes and give you the credit 🙂

 

How to add scheduled task to run php scripts in Windows

Few days ago, for one of our PHP / MySQL project, we were needed to run two php scripts at every minute. We usually develop/deploy our projects in LAMP environment, where we use crontab for our scheduled tasks. But our client have wanted us to run the system in Windows. So we have chosen  XAMPP. To run our two php scripts every 1 & 2 minute, we thought of developing a simple tool for windows which would run at background and execute those two php scripts. Fortunately we have found about schtasks, a native scheduler in Windows to run scheduled task smoothly in command prompt.

How to generate getter/setter in PHP easily

For one of my current project I need to write getter/setter functions for 20+ variables. You know, how annoying it is! Well, I can use magic quotes, but I don’t like it. More over getter setter will help you later to use the class when your IDE (in my case Netbeans) supports auto complete suggestion. Though all Java development environments allow to generate getter and setter code automatically.
Then I started coding a php script for generating getter/setter for supplied variables, but I was lucky as suddenly I thought “why don’t I look for something like this online” 🙂

And here is the link I got, its quite good. http://www.icurtain.co.uk/getset.php, It saved my time.

How to enable Apache HTTP Authentication using PHP

The easiest way to password-protect a site is to use HTTP Authentication, where if a browser’s request for a protected page is not accompanied by the correct username and password, the Web server replies with an HTTP 401 error – which means “Unauthorized Access” – and an invitation for the browser to re-submit the request with a proper username and password. From the user’s point of view, most of this dialogue is hidden. Following that first failed request, the browser prompts the user (in a dialog box) for a username and password, and then re-submits the request, this time with the authentication information attached. Assuming the username/password combo is on the list of allowed users, the Web server then sends the page requested. The Web browser will likewise continue to send that username/password with all subsequent requests.

Look at the following code: