Information Computer

Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Monday, August 15, 2011

PHP Date Function

While waiting for iftar. I want to continue post yesterday describing the functions of PHP. if yesterday we had know about the PHP string functions. Now we will discuss about the PHP date function.

Date function is used to retrieve the value in the date, hour, and all the things about the current time. The results of this function is a string which contains the date / hour according to the desired format. following the existing format in date function

a - "am" or "pm"
A - "AM" or "PM"
B - Swatch Internet time
d - day of the month, 2 digits with leading zeros; i.e. "01" to "31"
D - day of the week, textual, 3 letters; i.e. "Fri"
F - month, textual, long; i.e. "January"
g - hour, 12-hour format without leading zeros; i.e. "1" to "12"
G - hour, 24-hour format without leading zeros; i.e. "0" to "23"
h - hour, 12-hour format; i.e. "01" to "12"
H - hour, 24-hour format; i.e. "00" to "23"
i - minutes; i.e. "00" to "59"
I (capital i) - "1" if Daylight Savings Time, "0" otherwise.
j - day of the month without leading zeros; i.e. "1" to "31"
l (lowercase 'L') - day of the week, textual, long; i.e. "Friday"
L - boolean for whether it is a leap year; i.e. "0" or "1"
m - month; i.e. "01" to "12"
M - month, textual, 3 letters; i.e. "Jan"
n - month without leading zeros; i.e. "1" to "12"
s - seconds; i.e. "00" to "59"
S - English ordinal suffix, textual, 2 characters; i.e. "th", "nd"
t - number of days in the given month; i.e. "28" to "31"
T - Timezone setting of this machine; i.e. "MDT"
U - seconds since the epoch
w - day of the week, numeric, i.e. "0" (Sunday) to "6" (Saturday)
Y - year, 4 digits; i.e. "1999"
y - year, 2 digits; i.e. "99"
z - day of the year; i.e. "0" to "365"
Z - timezone offset in seconds (i.e. "-43200" to "43200")

sintax :

date (string format)

examples of the use of date functions :

date ("Ymd"); / / prints "2011-08-15"
date ("l, j FY"); / / prints "Monday, 15 August 2011"
date ("H: i: s"); / / prints "16:51:06"

very simple and very useful to complement your web page. may be useful for you. thank:)

need to know! 
In computer science, a subroutine (also called procedure, function, routine, method, or subprogram) is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code.

As the name "subprogram" suggests, a subroutine behaves in much the same way as a computer program that is used as one step in a larger program or another subprogram. A subroutine is often coded so that it can be started ("called") several times and/or from several places during a single execution of the program, including from other subroutines, and then branch back (return) to the next instruction after the "call" once the subroutine's task is done.

Subroutines are a powerful programming tool, and the syntax of many programming languages includes support for writing and using them. Judicious use of subroutines (for example, through the structured programming approach) will often substantially reduce the cost of developing and maintaining a large program, while increasing its quality and reliability. Subroutines, often collected into libraries, are an important mechanism for sharing and trading software. The discipline of object-oriented programming is based on objects and methods (which are subroutines attached to these objects or object classes).

In the compilation technique called threaded code, the executable program is basically a sequence of subroutine calls. Maurice Wilkes, David Wheeler, and Stanley Gill are credited with the invention of this concept, which they referred to as closed subroutine
READ MORE >> PHP Date Function

Sunday, August 14, 2011

PHP String Fungtions

how are you? hopefully fine. due to the following post I will discuss about the functions of a string in PHP. functions in PHPfunctions I will post it here. following functions are string functions that are often used.

string functions are the functions used to manipulate a string for a particular purpose. The following is a PHPstring functions.
  1. Addslash
    • Used to add a backslash character (\) on a string.It aims to use the query string to the database. examples of characters that need to be backslash (\) is the single quotes ('), two quotation marks ("), marks a backslash (\), and the null character.
    • sintax : addslash(string)
  2. Stripslash
    • Used to remove the backslash character (\) on a string.
    • sintax : stripslash(string)
  3. Crypt
    • Used to encrypt the DES method of a string. use of the crypt function can be added to a string parameter 'salt'. was added to determine the basis of randomization. If the 'salt' string is not added to the PHP crypt function will determine its own 'salt' is a random string.
    • sintax : crypt(string [, salt])
  4. Echo
    • Used to print the contents of a string or argument.
    • sintax : echo string
  5. Explode
    • Used to break up a string based on a specific list separator and put the result into a variable array
    • sintax : explode (separator string, string [, integer limit])
  6. Implode
    • used to generate a string from each of the elements of an array. The resulting string is separated by a string has been determined previously.
    • sintax : implode (separator string, array)
  7. StripTags
    • Used to remove the code in a string of HTML tags.
    • sintax : striptags (string [,string exceptions])
  8. StrLen
    • Used to calculate the number of characters of a string.
    • sintax : strlen (string)
  9. StrPos
    • Used to find the first position of a sub string in a string. This function is typically used to search a sub string within a string.
    •  sintax : strpos(string, sub string)
  10. Str_Repeat
    • Used to repeat the content of a string.
    • sintax : str_repeat(string , number of repetitions)
  11. StrToLower
    • Used to convert a string to lowercase
    • sintax : strtolower(string)
  12. StrToUpper
    • Used to convert a string to uppercase
    • sintax : strtoupper(string)
  13. SubStr
    • Used to retrieve a sub-string with a certain length of a string at a particular position as well.
    • sintax : substr(string , integer start position, integer end position)
  14. SubStr_Count
    • Used to calculate the number of substring in a string.
    • sintax : substr_count(string , string substring)
  15. UCFirst
    • Used to replace the first character in a string to uppercase.
    • sintax : ucfirst(string)
  16. UCWord
    • Used to replace the first character of each word in a string to uppercase.
    • sintax : ucword(string)
thank :)

need to know! 
In computer programming, a string is traditionally a sequence of characters, either as a literal constant or as some kind of variable. The latter may allow its elements to be mutated and/or the length changed, or it may be fixed (after creation). A string is generally understood as a data type and is often implemented as a byte (or word) array that stores a sequence of elements, typically characters, using some character encoding. A string may also denote more general array data types and/or other sequential data types and structures; terms such as byte string, or more general, string of datatype, or datatype-string, are sometimes used to denote strings in which the stored data does not (necessarily) represent text.

Depending on programming language and/or precise datatype used, a variable declared to be a string may either cause storage in memory to be statically allocated for a predetermined max length or employ dynamic allocation to allow it to hold chronologically variable number of elements. When a string appears literally in source code, it is known as a string literal and has a representation that denotes it as such.
READ MORE >> PHP String Fungtions

Saturday, August 13, 2011

Connect PHP With MySQL

The previous post I've described a little about MySQL functions in PHP. Maybe in your previous posts are still confused. Because I was just giving an explanation without an example.Following I will give an example of using the mysql functions in php. So, we will discuss examples of how to connect PHP with MySQL.

The first step we create a file named config.php which serves to connect a PHP file with MySQL.

config.php

<?php
mysql_connect("localhost","root","");
mysql_select_db("data");
?>

note :
"localhost" = hostname MySQL
"root"         = username MySQL
""                = password MySQL (password is not filled)
"data"         = database name

This is the default if you use XAMPP for local web server. Customize to your web server. Next create a file named index.php.

index.php

<?php
include('config.php');
$query= mysql_query("select * from table_data");
$rows = mysql_num_rows($query);
echo "Number of rows = $rows <p>";
while ($result = mysql_fetch_array($query)){
    echo "$result[0]<br>";
}
?>

note :
table_name = table name used (adjust yours).

if successful will appear as shown below




Connect PHP WIth MySQL


I hope this post helpful to us all. sorry if there is one word or a typo. sorry if things go wrong. ask if anyone on this please post a comment below. thank:)
READ MORE >> Connect PHP With MySQL

Monday, August 8, 2011

Mysql Functions In PHP

Earlier we know that PHP has a good connectivity to multiple databases. one of them with MySQL. because in PHP has several functions that are used to MySQL. The following functions.

mysql_connect (Host, Username, Password)
used to connect MySQL database with PHP files.
example : $var = mysql_connect("localhost","root","password").

mysql_close (variable_open_mysql)
used to close the MySQL database connection with PHP files.
example : mysql_close($var).

mysql_select_db(database name)
used to select the database that is used.
example : mysql_select_db("database").

mysql_query(query)
used to run a query.
example : $q = mysql_query("select * from data").

mysql_num_row(variable_query)
used to determine the number of rows in the result of a query.
example : $row = mysql_num_row($q).

mysql_fetch_array(query)
used to display the results of a query in the form of an array.
example : $result = mysql_fetch_array($q).

This new course may be necessary to be submitted. actually there are still others that I have not convey. therefore when the time comes I will update this article. thank :)

need to know! 
In computer science, a subroutine (also called procedure, function, routine, method, or subprogram) is a portion of code within a larger program that performs a specific task and is relatively independent of the remaining code.

As the name "subprogram" suggests, a subroutine behaves in much the same way as a computer program that is used as one step in a larger program or another subprogram. A subroutine is often coded so that it can be started ("called") several times and/or from several places during a single execution of the program, including from other subroutines, and then branch back (return) to the next instruction after the "call" once the subroutine's task is done.

Subroutines are a powerful programming tool, and the syntax of many programming languages includes support for writing and using them. Judicious use of subroutines (for example, through the structured programming approach) will often substantially reduce the cost of developing and maintaining a large program, while increasing its quality and reliability. Subroutines, often collected into libraries, are an important mechanism for sharing and trading software. The discipline of object-oriented programming is based on objects and methods (which are subroutines attached to these objects or object classes).

In the compilation technique called threaded code, the executable program is basically a sequence of subroutine calls. Maurice Wilkes, David Wheeler, and Stanley Gill are credited with the invention of this concept, which they referred to as closed subroutine
READ MORE >> Mysql Functions In PHP

Sunday, August 7, 2011

PHP

PHP stands for "Hypertext Preprocessor". PHP is a server-side scripting language that integrates with HTML to create dynamic web pages. so php is a scripting language that is attached to the HTML that is server-side.

server-side scripting is the syntax and commands given will be completely executed on the server but is included in an HTML document. so the server will run and process the PHP file and the browser will display a HTML file. so users will not be able to see the PHP program code and the security of a web page to be more secure

advantages and capabilities of PHP.
  1. Open Source (Free).
  2. With multiple OS support.
  3. Can send the HTTP header.
  4. May set cookies.
  5. set authentication and redirect users.
  6. good connectivity to multiple databases, such as
    • Oracle
    • Sybase
    • mSQL
    • MySQL
    • Solid
    • PostgreSQL
    • Adabas
    • File.Pro
    • Velocis
    • dBase
    • Unix dbm
  7. can integrate with several external libraries
  8. supports communication with other services
There are several ways to start writing PHP scripts.
  1. <?php Script PHP ?>
  2. <? Script PHP ?>
  3. <% Script PHP %>
  4. <script language=PHP>Script PHP</script>

Asked if there is please leave a message on this post. thank you for your attention :)

need to know! 
Server-side scripting is a web server technology in which a user's request is verified by running a script directly on the web server to generate dynamic web pages. It is usually used to provide interactive web sites that interface to databases or other data stores. This is different from client-side scripting where scripts are run by the viewing web browser, usually in JavaScript. The primary advantage to server-side scripting is the ability to highly customize the response based on the user's requirements, access rights, or queries into data stores.

From a security point of view, server-side scripts are never visible to the browser as these scripts are executed on the server and emit HTML corresponding to user's input to the page.

When the server serves data in a commonly used manner, for example according to the HTTP or FTP protocols, users may have their choice of a number of client programs (most modern web browsers can request and receive data using both of those protocols). In the case of more specialized applications, programmers may write their own server, client, and communications protocol, that can only be used with one another.

Programs that run on a user's local computer without ever sending or receiving data over a network are not considered clients, and so the operations of such programs would not be considered client-side operations..
READ MORE >> PHP

Tuesday, August 2, 2011

Ajax Javascript

May still be many who do not know what it was ajax. I think ajax is a web-based programming techniques used to create an interactive web application. Ajax is a combination of server side scripting and client side scripting. so ajax is some combination of Web programming such as javascript, PHP, DOM, HTML, and others.

ajax point will update the contents of a web without reloading process. ajax will do so working in an asynchronous data exchange. please note the exchange of data has 2 post and get methods. ajax script this time using two methods. The following examples use the ajax script.

if you try this script at home. Your computer must be installed xampp as a stand-alone server (localhost).

script file index.php

<html>
<head>
<script src=ajax.js></script>
</head>
<body>
<input type=text id=nama >
<input type=submit onclick=kirim("POST") value=POST>
<input type=submit onclick=kirim("GET") value=GET><br>
<div id=hasil />
<body>
</html>

script file ajax.js

var ajax;
if(window.ActiveXObject){
    ajax = new ActiveXObject("MicrosoftXMLHTTP");
}else {
    ajax = new XMLHttpRequest();
}

function proses(metode,url,params,id,output) {
    if (metode == 'POST'){
        ajax.open("POST",url,true);
        ajax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    }else{
        ajax.open("GET",url+'?'+params,true);
        params = null ;
    }
    ajax.onreadystatechange = function Response(){
        respon =  ajax.responseText;
        obj = document.getElementById(id) ;
        switch(output){
            case 'innerHTML' : obj.innerHTML = respon;
                break ;
        }
    }
    ajax.send(params);
}

function kirim(metode){
    id = "hasil" ;
    output = 'innerHTML' ;
    nama = document.getElementById('nama').value ;
    url = "ajax.php";
    var params = "nama="+escape(nama);

    proses(metode,url,params,id,output);
}

script file ajax.php

<?php
    if(isset($_POST['nama'])){
        $text1 = $_POST['nama'];
        echo $text1." <i>metode post</i>" ;
    }else if(isset($_GET['nama'])){
        $text2 = $_GET['nama'];
        echo $text2." <i>metode get</i>" ;
    }else{
        echo "null";
    }
?>

create a third file, and be simple ajax. thank :)
READ MORE >> Ajax Javascript

Followers