Subscribe For Free Updates!

We'll not spam mate! We promise.

May 21, 2014

MySQL query to trim particular character from database column field

MySQL has some default functions to trim particular cahr or whitespaces from all the column field in database rows. MySQL provide four type of methods to trim char.
1. TRIM()
2. TRIM(LEADING)
3. TRIM(BOTH)
4. TRIM(TRAILING)

we can use above four methods in select, update and delete queries.
1. TRIM()
    TRIM() function is used to remove the whitespaces from start and end of the string.
Query : select TRIM( TechniqZone );
Result : TechniqZone

    This is trim the whitespaces in all the column.
Example : update table_name set field1=TRIM(field1)
2. TRIM(LEADING)
    TRIM(LEADING) function is used to remove the given charecter from the starting postion of the string.
Query : select TRIM(LEADING "'" FROM "TechniqZone'");
Rssult : TechniqZone

  
    This method is remove the single quotes(') from al the column starting postion.
Example : update table_name set field1=TRIM(LEADING "'" FROM field1)
3. TRIM(BOTH)
    TRIM(BOTH) function is used to remove particular charecter from both start and end postion of the string.
Query : select TRIM(BOTH '"' FROM '"TechniqZone"');
Rssult : TechniqZone

    This is used to remove the double quotes (") from both position.
Example : update table_name set field1=TRIM(BOTH "'" FROM field1)
4. TRIM(TRAILING)
    TRIM(TRAILING) function is used to remove given charecter from end of the string.
Query : select TRIM(TRAILING '.com' FROM "TechniqZone.com");
Rssult : TechniqZone

    This MySQL query remove the .com from the end of the string.
Example : update table_name set field1=TRIM(TRAILING "xxx" FROM field1)
Note : TRIM() and TRIM(BOTH) is same as when we remove whitesapces from database column.
MySQL query to trim particular charecter from database column field - TechniqZone

May 20, 2014

Check String contains html tags and count of html tags using PHP

Check String contains html tags and count of html tags using PHP
Here i will explain how to check the given string contains html tags or not.  this function return boolean value.
// Function for check html tag presents
function hasTags($str){ 

$htmlTags = array('A' ,'B', 'BODY', 'BR', 'BUTTON', 'DIV', 'FONT', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'IMG', 'INPUT', 'TABLE');
// Here you mention what are the html tags you want to check
 if(preg_match_all("~(<\/?)\b(".implode('|',$htmlTags).")\b([^>]*>)~i",$str,$matches)){
       
return TRUE;
    }else{
        return 
FALSE;
    }
}

$str 'Welcome to <h1><b></b></h1>';

if(hasTags($str)){
    echo 
'HTML tags Found';
}else{
    echo 
'HTML tags not found';


If you want to get the present html tags count then consider the below function.

// Function for check html tag presents
function hasTags($str){
 $htmlTags
= array('A' ,'B', 'BODY', 'BR', 'BUTTON', 'DIV', 'FONT', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'IMG', 'INPUT', 'TABLE');



// Here you mention what are the html tags you want to check
if(preg_match_all("~(<\/?)\b(".implode('|',$htmlTags).")\b([^>]*>)~i",$str,$matches)){
        return
$matches[1];
    }else{
        return
0;
    }
}

$str 'Welcome to <h1><b></b></h1>';

echo 'Tags Count = '.hasTags($str);