Friday, July 9, 2010

PHP function to strip only selected tags

The following function is somewhat same with the php strip_tags function with added functionality to select what tags you want to strip.

function strip_only($str,$tags){
/*
usage:
echostrip_only($str,array('table','a'));
echostrip_only($str,'');
*/
if(!is_array($tags)){
$tags=(strpos($str,'>')!==false? explode('>',str_replace('<','',$tags)):array($tags));
if(
end($tags)=='')array_pop($tags);
}
foreach(
$tags as $tag)
$str=preg_replace('#.$tag.'[^>]*>#is','',$str);
return
$str;
}
?>

Javascript onclick return false does not work in IE6, IE7

Workaroud:

Instead of:

onclick="yourFunction(); return false;"

Use this:

onclick="yourFunction(); event.returnValue=false; return false;"

View genereated source in IE

You can view the generated source in IE just like on the Firefox Web Developer toolbar. Just copy and paste the code below in the URL then hit enter.

javascript:''+window.document.body.outerHTML+''

Email address validation using Javascript

In forms when using email ID fields it is a good idea to use client side validation along with your programming language validation. The following example shows how you can validate an email address for a form. The script is cross browser compatibe (works for all browsers).




Enter an Email Address :