Google adds english to hindi transliteration
Google did a great job in converting english to hindi. Google calls it as “Google Indic Transliteration”.
Give it a try and I am sure you will like it.
ActionForm – Reset multiple list <html:select multiple=”true”>
Struts uses ActionForm to both populate a HTML form, and then to capture the parameters when a form is submitted.
When a request is submitted, the ActionServlet matches the URI for the request against the path of an action-mapping. If there is a form-bean for that action-mapping, it looks for an ActionForm under the form-bean name. If it doesn’t find one, a new one is created. The ActionServlet then calls reset() on the new or pre-existing ActionForm and populates it from the request. If the action-mapping has validate set to true, the ActionServlet calls the validate method. If this returns any error messages, the ActionServlet forwards to the URI indicated by the action-mappings error property. This is often a JSP, but it can also be another action-mapping. The latter being needed when there are drop-down controls to populate and so forth. If there are no errors, the ActionServlet passes the (populated and validated) ActionForm to the Action indicated by the action-mapping element.
If you have a form with say a multiple select list, when you unselect items from the list and submit, the ActionForm class would not empty the collection. The easy way to fix it is by writing your own reset() method in which you simply initialize or empty the collection.
Downloading a page in PHP
If you ever need to download a HTTP/FTP or any page, try not to use fopen() and fread() functions. They work but will take enormous amounts of time as compared to curl functions. Try doing as follows:
To GET a page using a url
<?
$url=”http://any.url”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$xml = curl_exec ($ch);
curl_close ($ch);
?>
To POST to a page using values and fields:
<?
$url=”http://any.url”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, “fieldname=fieldvalue&fieldname=fieldvalue&”);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$store = curl_exec ($ch);
$content = curl_exec ($ch); # This returns HTML
curl_close ($ch);
?>
For more information, check the curl function on PHP website.
How to apply border to tables in Internet Explorer
IE does not acknowledge borders for the <tr> element. The only way to allow it is to trick IE by creating an illusion that the <td> element is continuous in a given <tr>.
To do that set the value of border-collapse property to collapse for the given table.
eg.
table { border-collapse:collapse; }
td { border-bottom:2px solid #000; }
PHP Data Objects
I was looking for a quick reference/tutorial to implement Data Objects with PHP, very similar to what exists in Java. Found a nice explanation at PHP Data Object
Validate e-mail address with regular expression
/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
All regular expressions start and end with forward slashes to differentiate them from ordinary string expressions. Most regular expressions start matches at the first character ^ and end at the last $.
Now we try to match the mailbox name which can include periods and dashes \w+ states one or more alphanumeric must be at the start of the name. ([\.-]?\w+)* allows periods or dashes to be included in the mailbox name with the trailing \w+ ensuring that those characters can not finish the name. The @ is the mandatory separator.
The domain name can have several .xx or .xyz suffixes such as .com.uk. Once again \w+ ensures that domain starts with an alphanumeric and ([\.-]?\w+)* allows for the dashes and periods. Finally (\.\w{2,3})+ ensures that there is at least one suffix of between 2 and 3 characters preceded by a period.
Note: This is not a completely foolproof validation as it does not account for new domain names of 4 or more characters. Also not all two and three letter combinations are legitimate domains!
Trim a string with all types of spaces
var a = “151 “;
a = a.replace(/^\s+|\s+$/, “”);
//a is now “151″ .
Note:
\s : Matches a single white space character, including space, tab, form feed, line feed.
Equivalent to [ \f\n\r\t\v\u00A0\u2028\u2029].
\S: Matches a single character other than white space.
Equivalent to [^ \f\n\r\t\v\u00A0\u2028\u2029].
