class Activate
{
function do()
{
return "it's good for you.";
}
}
if you want to use Activate::do() you will get an error.
class Activate
{
function do()
{
return "it's good for you.";
}
}
// to make the function language independent i put the array outside the functions
$array = array('zero','one','two','three','four','five','six','seven','eight','nine');
// number to words function
function d_to_w($digits,$array)
{
$temp = preg_split('//', $digits, -1, PREG_SPLIT_NO_EMPTY);
$return = array();
foreach($temp as $check)
{
if(is_numeric($check))
{
$return[] = $array[$check];
}
}
return implode(' ',$return);
}
// words to number function
function w_to_d($word,$array)
{
$temp = preg_split('/(\.|,|;|:| )/',$word, -1, PREG_SPLIT_NO_EMPTY);
$return = array();
foreach($temp as $check)
{
$temp2 = array_search(strtolower($check), $array);
if(is_numeric($temp2))
{
$return[] = $temp2;
}
}
return implode('',$return);
}
echo d_to_w('100',$array).'
'.w_to_d('one zero zero',$array).'
';
echo d_to_w('1.00',$array).'
'.w_to_d('one,zero zero',$array).'
';
$array = array(1,2,3);
foreach($array as $item);
{
echo $item;
}
$(function(){
// previously chosen theme
$.cookieswitchcss();
// elements that hold the alternate themes
$('.switchcss').switchcss();
});
$.fn.switchcss.defaults.linktitle = 'theme';
// gets the value of the title attribute of the anchors
$.fn.switchcss.defaults.themename = 'title';
$.cookieswitchcss();
$('a').switchcss();
class Datemodel extends Model
{
function Datemodel()
{
parent::Model();
}
/**
*
* interface functions
*
*/
function get($format = 'YmdHis', $date = null)
{
$date = (!isset($date))?$this->timestamp('db'):$this->dbformat($date);
return $this->format($date,$this->preformat($format));
}
function getstr($str,$format = 'YmdHis', $date = null)
{
$date = (!isset($date))?$this->timestamp('db'):$this->dbformat($date);
$sign = substr($str,0,1);
$period = trim(substr($str,1));
return $this->get($format,$this->interval($date,$sign,$period));
}
/**
*
* helper functions
*
*/
function timestamp($type = '')
{
switch($type)
{
case 'db': $query = $this->db->query('select NOW() as ts'); break;
default: $query = $this->db->query('select NOW()+0 as ts'); break;
}
$row = $query->row();
return $row->ts;
}
function format($date,$format)
{
$query = $this->db->query('select date_format("'.$date.'","'.$format.'") as val');
$row = $query->row();
return $row->val;
}
function interval($date,$sign,$period)
{
switch($sign)
{
case '+': $query = $this->db->query('select date_add("'.$date.'", interval '.$period.') as val'); break;
case '-': $query = $this->db->query('select date_sub("'.$date.'", interval '.$period.') as val'); break;
}
$row = $query->row();
return $row->val;
}
function dbformat($date)
{
if(strlen($date) == 14)
{
$year = substr($date,0,4);
$month = substr($date,4,2);
$day = substr($date,6,2);
$hour = substr($date,8,2);
$min = substr($date,10,2);
$sec = substr($date,12,2);
$date = $year.'-'.$month.'-'.$day.' '.$hour.':'.$min.':'.$sec;
}
return $date;
}
function preformat($str)
{
$array = array('%','a','b','c','d','e','h','i','j','k','l','m','p','r','s','u','v','w','x','y','D','H','I','M','S','U','V','W','X','Y');
foreach($array as $char)
{
$str = str_replace($char,'%'.$char,$str);
}
return $str;
}
}
?>
class Datemodel extends Model
{
function Datemodel()
{
parent::Model();
}
/**
*
* interface functions
*
*/
function get($format = 'YmdHis', $date = null)
{
if(!isset($date)){ $date = $this->timestamp('db'); }
return $this->format($date,$this->preformat($format));
}
function getstr($str,$format = 'YmdHis', $date = null)
{
if(!isset($date)){ $date = $this->timestamp('db'); }
$sign = substr($str,0,1);
$period = trim(substr($str,1));
return $this->get($format,$this->interval($date,$sign,$period));
}
/**
*
* helper functions
*
*/
function timestamp($type = '')
{
switch($type)
{
case 'db': $query = $this->db->query('select NOW() as ts'); break;
default: $query = $this->db->query('select NOW()+0 as ts'); break;
}
$row = $query->row();
return $row->ts;
}
function format($date,$format)
{
$query = $this->db->query('select date_format("'.$date.'","'.$format.'") as val');
$row = $query->row();
return $row->val;
}
function interval($date,$sign,$period)
{
switch($sign)
{
case '+': $query = $this->db->query('select date_add("'.$date.'", interval '.$period.') as val'); break;
case '-': $query = $this->db->query('select date_sub("'.$date.'", interval '.$period.') as val'); break;
}
$row = $query->row();
return $row->val;
}
function preformat($str)
{
$array = array('%','a','b','c','d','e','h','i','j','k','l','m','p','r','s','u','v','w','x','y','D','H','I','M','S','U','V','W','X','Y');
foreach($array as $char)
{
$str = str_replace($char,'%'.$char,$str);
}
return $str;
}
}
?>
echo time();
echo date('U');
function tsgen($fromnow = '',$ts = '')
{
if($fromnow == '')
{
return ($ts == '')?time():date($ts);
}
else
{
if(is_array($fromnow))
{
$tempbegin = array_shift($fromnow);
$timestamp = strtotime($tempbegin);
if($timestamp == -1){ $timestamp = false; }
if (!$timestamp) {
return false;
}
else
{
$error = 0;
foreach($fromnow as $str)
{
$timestamp = strtotime($str,$timestamp);
if($timestamp == -1){ $timestamp = false; }
if (!$timestamp) { $error++; }
}
if($error > 0)
{
return false;
}
else
{
return ($ts == '')?$timestamp:date($ts,$timestamp);
}
}
}
else
{
if(is_numeric($fromnow) && strlen($fromnow) == 14)
{
return mktime(substr($fromnow,8,2), substr($fromnow,10,2), substr($fromnow,12,2), substr($fromnow,4,2), substr($fromnow,6,2), substr($fromnow,0,4));
}
else
{
$timestamp = strtotime($fromnow);
if($timestamp == -1){ $timestamp = false; }
if (!$timestamp) {
return false;
}
else
{
return ($ts == '')?$timestamp:date($ts,$timestamp);
}
}
}
}
}
echo tsgen();
echo tsgen('+1 day');
echo tsgen(20070101010101);
echo tsgen(array('+28 days','last friday'));
echo tsgen('next month','d-m-Y');
for($i=0;$i<10;$i++){
?><p><input type="image" name="button<?php echo $i; ?>" src="image.jpg" value="button"></p><?php
}
for($i=0;$i<10;$i++){
if(strlen(array_search('button'.$i.'_x',array_keys($_POST))) > 0){
// do something
}
}
$click = $_POST['test_x'];
if($click > 24){
$test = 'Delete button';
}else{
$test = 'Update button';
}
<asp:DataGrid ID="datagrid" runat="server" AutoGenerateColumns="false" ShowFooter="true"
OnEditCommand="datagridEdit" OnCancelCommand="datagridCancel" OnUpdateCommand="datagridUpdate" OnItemDataBound="datagridBound" OnItemCommand="datagridVarCommands" >
<HeaderStyle CssClass="th" />
<AlternatingItemStyle CssClass="even" />
<SelectedItemStyle CssClass="editrow" />
<Columns>
<asp:BoundColumn HeaderText="Id" DataField="id" Visible="false" ReadOnly="true"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Title">
<ItemTemplate><asp:Literal ID="title" runat="server"></asp:Literal></ItemTemplate>
<EditItemTemplate><asp:TextBox ID="editTitle" runat="server"></asp:TextBox></EditItemTemplate>
<FooterTemplate><asp:TextBox ID="addTitle" runat="server">></asp:TextBox></FooterTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn HeaderText="" EditText="Edit Info" UpdateText="Update" CancelText="Cancel"></asp:EditCommandColumn>
<asp:TemplateColumn HeaderText="">
<ItemTemplate><asp:LinkButton CommandName="Delete" Text="Delete" ID="btnDel" Runat="server" /></ItemTemplate>
<FooterTemplate><asp:LinkButton CommandName="Insert" Text="Toevoegen" ID="btnAdd" Runat="server" /></FooterTemplate>
</asp:TemplateColumn>
void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Data();
}
}
public void Data()
{
try
{
conn.Open();
string sql = "select id, title,description,online from Content order by title";
SqlCommand com = new SqlCommand(sql, conn);
SqlDataAdapter myDA = new SqlDataAdapter();
myDA.SelectCommand = com;
DataSet myDS = new DataSet();
myDA.Fill(myDS);
datagrid.DataSource = myDS;
datagrid.DataBind();
}
catch (SqlException ex)
{
message.Text = ex.Message;
}
catch (Exception ex)
{
message.Text = ex.Message;
}
finally
{
conn.Close();
}
}
public void datagridBound(Object sender, DataGridItemEventArgs e)
{
// get bound data row
DataRowView row = (DataRowView)e.Item.DataItem;
switch(e.Item.ItemType)
{
// @@@@ EDIT TEMPLATE
case ListItemType.EditItem:
((TextBox)e.Item.FindControl("editTitle")).Text = row["title"].ToString();
((TextBox)e.Item.FindControl("editContent")).Text = row["description"].ToString();
if ("1" == row["online"].ToString()) { ((CheckBox)e.Item.FindControl("editOnline")).Checked = true; }
break;
// @@@@ REGULAR TEMPLATES
case ListItemType.AlternatingItem:
case ListItemType.Item:
((Literal)e.Item.FindControl("title")).Text = row["title"].ToString();
((Literal)e.Item.FindControl("content")).Text = row["description"].ToString();
string online = "No";
if("1" == row["online"].ToString()){ online = "Yes"; }
((Literal)e.Item.FindControl("online")).Text = online;
break;
}
}
<ItemTemplate><%# DataBinder.Eval(Container, "DataItem.id")%></ItemTemplate>
public void datagridEdit(Object sender, DataGridCommandEventArgs e)
{
datagrid.EditItemIndex = (int)e.Item.ItemIndex;
Data();
}
public void datagridCancel(Object sender, DataGridCommandEventArgs e)
{
datagrid.EditItemIndex = -1;
Data();
}
public void datagridUpdate(Object sender, DataGridCommandEventArgs e)
{
message.Text = "<p>Updated row:</p><p>Id : " + e.Item.Cells[0].Text + "</p>";
message.Text += "<p>Title : " + ((TextBox)e.Item.FindControl("editTitle")).Text+"</p>";
message.Text += "<p>Content : " + ((TextBox)e.Item.FindControl("editContent")).Text + "</p>";
string online = "No";
if (((CheckBox)e.Item.FindControl("editOnline")).Checked) { online = "Yes"; }
message.Text += "<p>Online : " + online + "</p>";
Data();
}
public void datagridVarCommands(Object sender, DataGridCommandEventArgs e)
{
switch(e.CommandName)
{
// !!!! DELETE
case "Delete":
message.Text = "<p>Delete row</p><p>Id : " + e.Item.Cells[0].Text + "</p>";
break;
// !!!! ADD
case "Insert":
message.Text = "<p>Insert row:</p>";
message.Text += "<p>Title : " + ((TextBox)e.Item.FindControl("addTitle")).Text + "</p>";
message.Text += "<p>Content : " + ((TextBox)e.Item.FindControl("addContent")).Text + "</p>";
string online = "No";
if (((CheckBox)e.Item.FindControl("addOnline")).Checked) { online = "Yes"; }
message.Text += "<p>Online : " + online + "</p>";
break;
}
}
<link rel="stylesheet" type="text/css" href="css/default.all.css">
<!--[if IE]> <link href="css/default.ie.css" rel="stylesheet" type="text/css"> <![endif]-->
<!--[if lte IE 7]> <link href="css/default.ie7.css" rel="stylesheet" type="text/css"> <![endif]-->
<!--[if lte IE 6]> <link href="css/default.ie6.css" rel="stylesheet" type="text/css"> <![endif]-->
<!--[if !IE]>--> <link href="css/default.non.ie.css" rel="stylesheet" type="text/css"> <!--<![endif]-->
<!--# file="c:\httpdocs\site\\test.aspx" -->
<!--# virtual="/site/testpage" -->
int test = Convert.ToInt32(Request.QueryString["test"]);
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.Odbc" %>
<script language="c#" runat="server">
// variables
int number = 1;
string query = "SELECT name FROM testtable WHERE id = ?";
// prepare connection
OdbcConnection conn = new OdbcConnection("Driver={Mysql Odbc 3.15 Driver}; Server=localhost; Database=test; User=user; Password=password; Option=3;");
// prepare database connection
OdbcCommand com = new OdbcCommand(query, conn);
// add value to query string
com.Parameters.Add("",OdbcType.BigInt, 20).Value = number;
// start error handling
try
{
// open connection
conn.Open();
// get database result
OdbcDataReader reader = com.ExecuteReader();
// process database result
while(reader.Read())
{
textboxName.Text = reader.GetString(0);
}
// because it's a single result it can be shorter
textboxName2.Text = com.ExecuteScalar();
reader.Close();
}
// database error
catch (OdbcException ex)
{
labelMessage.Text = ex.Message;
}
// general errors
catch (Exception ex)
{
labelMessage.Text = ex.Message;
}
finally
{
conn.Close();
}
</script>
<html>
<head>
<title>test</title>
</head>
<body>
<p><asp:Label id="labelMessage" runat="server" /></p>
<p><input type="text" id="textboxName" runat="server" /></p>
<p><input type="text" id="textboxName2" runat="server" /></p>
</body>
</html>
START c:\start\%1
function name($arg1,$arg2='optional',$arg3='optional'){
echo $arg1.' '.$arg2.' '.$arg3;
}
def name(arg1,arg2='optional',arg3='optional'):
print arg1, arg2, arg3
name(1);
name(1,2,3);
name(1,'optional',3);
function name($arg1,$array){
echo $arg1;
$arg2 = ' optional';
$arg3 = ' optional';
if(count($array) == 0){
echo $arg2.$arg3;
}else{
foreach($array as $key => $value){
if($value != ''){
switch($key){
case 'arg2': echo $arg2; break;
case 'arg3': echo $arg3; break;
}
}
}
}
}
name(1)
name(1,2,3)
name(1,arg3=3)
name(1,arg2=2,3)
listtest = [1,2]
name(*listtest)
dicttest = {'arg1': 1, 'arg2': 2}
name(**dicttest)