Thursday, 28 July 2011

10 Powerful PHP Regular Expression For Developers

Regular expressions are more powerful tool for web developers that allows you to modifying text, identify, replace words or any type of characters. With the help of these expressions developers can search matching string of text, words and pattern characters. Have you note that, regular expressions are more slower than the basic string function, its takes a short time to execute than any others.
In computing, a regular expression, also referred to as regex or regexp, provides a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters. For more Information( Wikipedia).
Regular expression for the PHP developers, on of the most popular tool for validating data is the regular expression. In this list we provides some validation – string match, password match validation, email address validation, date format and many more which helps developer to make their application more fast and easy to execute.

Visit this list and used these validation with line of code and make your project easy. Thanks a lot to readers for appreciate our previous articles.

1) String Mtach

2) Password Match Validation

3) Email Address Validation

4) Date Format Validation

5) Validate URL

6) Validate  URL using Preg_match

7) Email Validation Using ereg

8 ) IP Address Matching Valdation

9) UK Postcode Validation

10) SSN,ISBN and Zipcode Validation

Monday, 25 July 2011

Quicktip – Convert .po files to .php (PHP array)

Multilanguage websites or webapplications are state-of-the-art today. You have a lot of choices in translation technology, language, format, etc. gettext is one of the most popular libraries to use. There are some downsides using gettext. One of the bad things is that you need to compile your .po files to .mo files before deployment. So, I decided to use PHP arrays instead of .po files for my translation strings. In order to convert my existing .po files, I wrote a little 5-minute script :-), which prints out a php file with a php array, according to the .po file.

<?php

$file = '/data/workspaces/tutorial/portal/lang/de_DE/LC_MESSAGES/portal.po';
$translations = array();
$po = file($file);
$current = null;
foreach ($po as $line) {
    if (substr($line,0,5) == 'msgid') {
        $current = trim(substr(trim(substr($line,5)),1,-1));
    }
    if (substr($line,0,6) == 'msgstr') {
        $translations[$current] = trim(substr(trim(substr($line,6)),1,-1));
    }
}

echo "<?php\n\n";
foreach ($translations as $msgid => $msgstr) {
    echo "$lang['" . $msgid . "'] = '" . $msgstr . "';\n";
}
echo "\n?>";

?>
This prints out something like
<?php

$lang['January'] = 'Januar';
$lang['February'] = 'Februar';
$lang['March'] = 'März';
$lang['April'] = 'April';

?>