July 14th, 2008
The other day on the DigitalPoint webmaster forums, I had somebody ask this question “How to half-disable a form field”.
From all the HTML I knew, it was not possible in a straight-forward way! But we can manipulate with CSS.
The HTML-CSS
<span style="border: 2px inset;">
<input style="border: none; text-align: right;" name="half_1" size="3" type="text" value="ABC" />
<input style="background: #FFFFFF; border: none;" name="half_2" readonly="readonly" size="3" type="text" value="123" />
</span> |
3 Comments |
CSS, Web designing |
Permalink
Posted by Rohan Shenoy
July 12th, 2008
Regular expressions by themselves are difficult for many to implement. An error that many of the regex newbies will encounter is:
Warning: preg_match() [function.preg-match]: Unknown modifier ‘/’ in ….. on line …
Solution
This error occurs whenever the pattern you are looking for contains a literal forward-slash. You should escape every literal forward-slash with a backslash.
For those of you interested in knowing more
The syntax for preg_match() is
int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags [, int $offset ]]] ) |
Example of a pattern to search for alphabetic substrings in a string would be:
In the above, pattern example, the two forward slashes you see are the delimiters. The PHP parser is programmed to understand that anything in-between those two delimiters is the actual pattern we are looking for. However, the pattern we just used above will look only for lowercase alphabets. If we want PHP to look for even upper case or mixed case substrings, we need to inform the PHP parser accordingly.
All such additional instructions are provided to the PHP parser using entities which are called as ‘modifiers’. These modifiers are placed at the end of the pattern, after the delimiting forward-slash. Look below to see how we place the modifier named ‘i’ to instruct PHP parser to do a case-insensitive pattern matching
Any character appearing after the end delimiting forward slash is ‘assumed’ by the PHP parser as a delimited. A number of delimiters are defined by PHP. A full list of modifiers can be found here.
If you forget to escape a literal forward-slash in your pattern parameter, PHP assumes that the pattern has been ended by the delimiter and characters after that forward-slash are ‘modifiers’. When the parser finds that the modifiers are not defined by PHP, its outputs the error saying ‘Unknown modifier’.
No Comments » |
PHP-MySQL |
Permalink
Posted by Rohan Shenoy
July 7th, 2008
Since I work with PHP as well as JavaScript, I know that there is no easy in-built function in JS to check if a given key exists or not in a JavaScript array object. Google-ing for the same returned some user-made functions that were either too long and complicated or even impractical with huge arrays.
The below small snippet works just fine:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| <script type="text/javascript">
//lets setup a sample array and its key-and-values
var array=new Array();
array['name']='Rohan Shenoy';
array['gender']='Male';
array['age']='21';
//lets try to find an key which exists
if(array['name']==undefined)
{alert('That key is undefined');}
else
{alert('That keys exists');}
//lets try to find an key which does NOT exist
if(array['residence']==undefined)
{alert('That key is undefined');}
else
{alert('That keys exists');}
</script> |
As simple as that!
No Comments » |
JavaScript/AJAX |
Permalink
Posted by Rohan Shenoy