Categories
PHP

A Handy alphabet class :)

Another funny class with no serious use. This is a class I wrote to determine the numerical positions of letters in the English alphabet.

How to use ?

As you can see, using the getNum() method, you can feed a letter and get the serial number or numerical position of that letter. Again in the same way, use the getChar() method to input a number and get the character/letter in that position.

I use it very often while breaking alphabet related codes.

Source Codes:

Categories
PHP

Decoding Google’s Tweet With PHP

This is something for fun — nothing serious. It just happened that Google just sent a mysterious Tweet around 2 hours ago from now with an image with of the Google home page featuring an UFO. The UFO was seen pulling an O out of the google logo. But what the heck does that tweet mean ?

1.12.12 25.15.21.18 15 1.18.5 2.5.12.15.14.7 20.15 21.19 was the tweet.

Well, it’s nothing tough. Every number separated by a dot or space corresponds to the alphabet. So, I wrote a PHP script to decode this mysterious tweet and finally found the meaning:

So, it meant ” all your o are belong to us ” 😉
Sounds a bit odd ? Or wrong in grammar ? yeah, still, that’s the message. It is confirmed on the twitpic image.

And here’s the source code —

It was quite a bit of fun decoding the message with PHP. Well, I do agree that there was no need to use PHP here. But why do the hard work from memory when you have automation tools at your hand 😉 ?

Categories
PHP

PHP: Counting Occurrences with PCRE

While playing with PHP, I have found a fact that we can determine how many times a string occurs inside another string quite easily by using PCRE. In fact, we can use preg_match_all() to match a string (instead of a complex pattern) to another string and get the matches as an array. Then we count() the array’s first key to know how many times the string has been found in the other one.

We feed preg_match_all() a solid string as a pattern as the first parameter. And it’d do the job for us.

Here’s the code snippet:

In the above example, we add an “i” modifier for case insensitive matching. If you want it to be a case sensitive matching, just ignore the “i” modifier.

Results:

Additionally this method can be used instead of strpos() when we try to find if a string exists in another.