Saturday, January 31, 2015

PHP and JavaScript, check a string contains a substring



In PHP, we  use strpos to check if a string contains a substring.
strpos function— Find the position of the first occurrence of a substring in a string, it  may return 0 as it's index value.
 If you do a == compare that will not work, you will need to do a ===.
A == sign is a comparison and tests whether the variable / expression / constant to the left has the same value as the variable / expression / constant to the right.
A === sign is a comparison to see whether two variables / expressions / constants are equal AND have the same type - i.e. both are strings or both are integers.

Example:
1) to check $contract string contains "Sessional" substring in PHP
if(strpos($contract, 'Sessional') ! = = false)
2) to check $contract string does not contain "Sessional" substring in PHP
if(strpos($contract, 'Sessional') = = = false)

 In  JavaScript, we use indexOf function
The indexOf() method returns the position of the first occurrence of a specified value in a string.
This method returns -1 if the value to search for never occurs.

Example
 1) to check contract string contains "Sessional" substring in JS
if( contract.indexOf("Sessional")!=-1)

 2) to check contract string does not contain "Sessional" substring in JS
if( contract.indexOf("Sessional") = = -1)

More about string operation in Javascript
In JavaScript, To get  the the first character of string contract, we use
contract.charAt(0)

To get a substring of a string for example
term1=(term).substring(0,4);
where 0 is start position, and 4 is end position, but not included.
To trim a string for example term
term.trim();
or using jQuery
$.trim(term)

Similarly in PHP we have substr function,
for example
echo substr('abcdefg', 0, 4);
return abcd, also not including end position.

Sunday, January 25, 2015

Remove ads agent and improve Internet security in FireFox




You may not notice there are some background ads agent running when you use Firefox even you installed Anti-virus. In the worst case, your personal information may be posted to other websites and stolen.

To check and remove  suspicious programs in your computer:

1. In Firefox, go to menu and click Add-ons, go to Extension,
enable anti-virus, go to plugins, select "never activate" or
remove suspicious programs.

2. Go to control panel,  go to programs and features, uninstall programs in Windows,  find suspicious programs installed lately (click installed on to sort by installation date)  and remove.

3. In Firefox,  go to google.com or other address,  go to Firefox menu, click developer and click network and reload, find if your data are posted to some suspicious websites.

Video: Remove  ads agent and improve Internet security in Fire Fox