Tuesday, March 23, 2010

function that removes the HTML tags along with their contents in php

function strip_tags_content($text, $tags = '', $invert = FALSE) {

preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
$tags = array_unique($tags[1]);

if(is_array($tags) AND count($tags) > 0) {
if($invert == FALSE) {
return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?@si', '', $text);
}
else {
return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?@si', '', $text);
}
}
elseif($invert == FALSE) {
return preg_replace('@<(\w+)\b.*?>.*?@si', '', $text);
}
return $text;
}
Sample text:
$text = 'sample text with
tags
';

Result for strip_tags($text):
sample text with tags

generating Unique random key in php

function get_cripta()
{
$year = date('Y');
$month = date('m');
$day = date('d');
$hour = date('H');
$min = date('i');
$sec = date('s');
$coef = rand(1,99999);
$quo1 = ($year*$month*$day);
$quo2 = ($hour+$min+$sec);
$result = ($quo1*$quo2)*$coef;
$final = md5($result);
return $final;
}

Date and Time Zone in php

Function to get Date format by time zone:
function get_date(DateTime $time)
{

$t = clone $time;
// set time zone here
$t->setTimezone(new DateTimeZone("America/Denver"));
return $t->format("Y-m-d H:i:s");
}
?>
// usages
$date ="2008-08-03 14:52:10";
$datetime = date_create($date);
echo get_ebay_UTC_8601($datetime);
?>

Monday, February 9, 2009

silverlight sql data grid

http://silverlight.net/learn/tutorials/sqldatagrid.aspx

Monday, January 19, 2009

डेट परसे इन sql

DateTime.Parse(Request["ctl00$ContentPlaceHolder1$GridView1$ctl0"+Rownum.ToString()+"$txt_date"], new CultureInfo("fr-FR", false));

Friday, January 16, 2009

Using DropDownList control in DataGrid

http://www.csharphelp.com/archives/archive212.html

GridView add multiple controls to edit item template


Text='<%# Bind("project") %>'>
OnClick="LinkButton3_Click">PV

Reading values from Gridview Item Templates

//write this coding in gridview1_RowUpdating event // Read the values from Text Box String name = ((TextBox)(gridview1.Rows[e.RowIndex].FindControl("NAME"))).Text; //Read the values from Label String ID = ((Label)(dgSummary.Rows[e.RowIndex].FindControl("ID"))).Text; //Read Html Check Box value boolean bol=((HtmlInputCheckBox)(gridview1.Rows[e.RowIndex].FindControl("CheckBox1"))).Checked

An API for Google Image Search

find the url listed below

http://www.codeproject.com/KB/IP/google_image_search_api.aspx

Upload any type of File through a C# Web Service

http://www.c-sharpcorner.com/UploadFile/scottlysle/UploadwithCSharpWS05032007121259PM/UploadwithCSharpWS.aspx

Get Values from CheckBoxList

String values = "";
for (int i=0; i< cbl.Items.Count; i++)
{
if(cbl.Items[i].Selected)
{
values += cbl.Items[i].Value + ",";
}
}

values = values.TrimEnd(',');

How to get the Content Type(MimeType) of a file

private string MimeType (string Filename)
{
string mime = "application/octetstream";
string ext = System.IO.Path.GetExtension(Filename).ToLower();
Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);
if (rk != null && rk.GetValue("Content Type") != null)
mime = rk.GetValue("Content Type").ToString();
return mime;
}

Wednesday, January 14, 2009

displaying gridview row index number



<%# Container.DataItemIndex + 1 %>

Dropdown in Gridview in Asp.net









DataSource="<%# GetProjectDs() %>"
DataTextField="PROJECT_NAME"
DataValueField="PROJECT_ID"
SelectedIndex='<%# GetProjectSelectedIndex((int)DataBinder.Eval(Container.DataItem,"PROJECT_ID")) %>'
>







DataSource="<%# GetTaskDs() %>"
DataTextField="TASK_NAME"
DataValueField="TASK_ID"
SelectedIndex='<%# GetTaskSelectedIndex((int)DataBinder.Eval(Container.DataItem, "TASK_ID")) %>'
/>




pick date









,'view_time_sheet.aspx?action=delete')">Delete Task
  ,<%# Container.DataItemIndex + 2 %>)">Update Task