Friday, May 24, 2013

What is mysql_free_result()?


mysql_free_result() only needs to be called if you are concerned about how much memory is being used for queries that return large result sets. All associated result memory is automatically freed at the end of the script's execution.
Returns TRUE on success or FALSE on failure.

How to use mysql_fetch_object?

object mysql_fetch_object ( resource result)


Returns an object with properties that correspond to the fetched row, or FALSE if there are no more rows.
mysql_fetch_object() is similar to mysql_fetch_array(), with one difference - an object is returned, instead of an array. Indirectly, that means that you can only access the data by the field names, and not by their offsets (numbers are illegal property names).
Note: Field names returned by this function are case-sensitive.


<?php
/* this is valid */echo $row->field;/* this is invalid */echo $row->0;
?>



<?php
mysql_connect
("hostname", "user", "password");mysql_select_db("mydb");$result = mysql_query("select * from mytable");
while (
$row = mysql_fetch_object($result)) {
    echo
$row->user_id;
    echo
$row->fullname;
}
mysql_free_result($result);?>

How to use mysql_fetch_assoc?

array mysql_fetch_assoc ( resource result)


Returns an associative array that corresponds to the fetched row, or FALSE if there are no more rows.
mysql_fetch_assoc() is equivalent to calling mysql_fetch_array() with MYSQL_ASSOC for the optional second parameter. It only returns an associative array. This is the way mysql_fetch_array() originally worked. If you need the numeric indices as well as the associative, use mysql_fetch_array().
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you either need to access the result with numeric indices by using mysql_fetch_row() or add alias names. See the example at the mysql_fetch_array() description about aliases.
An important thing to note is that using mysql_fetch_assoc() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value.

An expanded mysql_fetch_assoc() example

<?php

$conn
= mysql_connect("localhost", "mysql_user", "mysql_password");

if (!
$conn) {
    echo
"Unable to connect to DB: " . mysql_error();
    exit;
}
   
if (!
mysql_select_db("mydbname")) {
    echo
"Unable to select mydbname: " . mysql_error();
    exit;
}
$sql = "SELECT id as userid, fullname, userstatus
        FROM   sometable
        WHERE  userstatus = 1"
;
$result = mysql_query($sql);

if (!
$result) {
    echo
"Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (
mysql_num_rows($result) == 0) {
    echo
"No rows found, nothing to print so am exiting";
    exit;
}

while ($row = mysql_fetch_assoc($result)) {
    echo
$row["userid"];
    echo
$row["fullname"];
    echo
$row["userstatus"];
}
mysql_free_result($result);
?>

Saturday, May 18, 2013

How to use mysql_connect() example

<?php
$link
= mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!
$link) {
    die(
'Could not connect: ' . mysql_error());
}
echo
'Connected successfully';mysql_close($link);?>

How to use mysql_affected_rows?

mysql_affected_rows -- Get number of affected rows in previous MySQL operation

mysql_affected_rows() returns the number of rows affected by the last INSERT, UPDATE or DELETE query associated with link_identifier. If the link identifier isn't specified, the last link opened by mysql_connect() is assumed.

Example
<?php/* connect to database */$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!
$link) {
    die(
'Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');
/* this should return the correct numbers of deleted records */mysql_query('DELETE FROM mytable WHERE id < 10');printf("Records deleted: %d\n", mysql_affected_rows());
/* with a where clause that is never true, it should return 0 */mysql_query('DELETE FROM mytable WHERE 0');printf("Records deleted: %d\n", mysql_affected_rows());?>


Output:

Records deleted: 10
Records deleted: 0



Example2
<?php/* connect to database */mysql_connect("localhost", "mysql_user", "mysql_password") 
or
    die("Could not connect: " . mysql_error());mysql_select_db("mydb");
/* Update records 
*/mysql_query("UPDATE mytable SET used=1 WHERE id 
< 10");printf 
("Updated records: 
%d\n", mysql_affected_rows());mysql_query("COMMIT");?> 
Output


Updated Records: 10


Friday, May 17, 2013

What is the use of "ksort" in php?


it is used for sort an array by key in reverse order.

How to calculate the sum of values in an array ?


"array_sum" method used for calculate sum of values in an array

Differences between GET and POST methods ?


We can send 1024 bytes using GET method but POST method can transfer large amount of data and POST is the secure method than GET method .

How to retrieve the data from MySQL result set ?


using the methods given below 
1. mysql_fetch_row. 
2. mysql_fetch_array 
3. mysql_fetch_object 
4. mysql_fetch_assoc



mysql_fetch_array() is an extended version of mysql_fetch_row(). In addition to storing the data in the numeric indices of the result array, it also stores the data in associative indices, using the field names as keys.
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you must use the numeric index of the column or make an alias for the column. For aliased columns, you cannot access the contents with the original column name (by using 'field' in this example).

mysql_fetch_array() with MYSQL_NUM
<?php
mysql_connect
("localhost", "mysql_user", "mysql_password") or
    die(
"Could not connect: " . mysql_error());mysql_select_db("mydb");
$result = mysql_query("SELECT id, name FROM mytable");

while (
$row = mysql_fetch_array($result, MYSQL_NUM)) {
    
printf("ID: %s  Name: %s", $row[0], $row[1]); 
}
mysql_free_result($result);?> 

What is use of in_array() function in php ?


in_array used to checks if a value exists in an array

what is the use of the function " explode() " in php?


This function is used to split a string by special character or symbol in the string, we must be pass the string and splitting character as parameter into the function.

How to create a mysql connection?


mysql_connect(servername,username,password);

Difference between mysql_connect and mysql_pconnect?


There is a good page in the php manual on the subject, in short mysql_pconnect() makes a persistent connection to the database which means a SQL link that do not close when the execution of your script ends.

 mysql_connect()provides only for the database new connection while using mysql_pconnect , the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection... the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use.

What is difference between require_once(), require(), include(). them?


require() includes and evaluates a specific file, 
while require_once() does that only if it has not been included before (on the same page). So, require_once() is recommended to use when you want to include a file where you have a lot of functions for example. This way you make sure you don't include the file more times and you will not get the "function re-declared" error.

What’s the difference between include and require?


If the file is not found by require(), it will cause a fatal error and halt the execution of the script. 
If the file is not found by include(), a warning will be issued, but execution will continue.

How to include a file to a php page?


we can include a file using "include() " or "require()" function with as its parameter.

Wednesday, May 15, 2013

How Sessions Work?



Session are handled in PHP by using the function session_start(). This function should be invoked before any HTML tags in the script.
Ex. 
<?php
session_start( );
?>
<html>
<head> ....... etc
A random session id is generated by the function session_start(). This session id is persisted in a cookie on the client / user computer. To refer the cookie, the reference variable $PHPSESSID is used. This is the default session id. The session id can be changed in the PHP configuration files on the server.
Even the user returns this page after visiting some pages, PHP keeps track about this session and its progress. Subsequent to this process, the session can be used as follows –
print $PHPSESSID; 
session_register("username");
 
print $username;
The user name is registered and by using session variable name username and used it for display.
....... etc A random session id is generated by the function session_start(). This session id is persisted in a cookie on the client / user computer. To refer the cookie, the reference variable $PHPSESSID is used. This is the default session id. The session id can be changed in the PHP configuration files on the server. Even the user returns this page after visiting some pages, PHP keeps track about this session and its progress. Subsequent to this process, the session can be used as follows – print $PHPSESSID; session_register("username"); print $username; The user name is registered and by using session variable name username and used it for display.

What is the difference between echo and print statement?


Monday, May 13, 2013

Explain with code how to get a user's IP address


Identifying the IP address is a very important requirement, using which the visitor’s details could be persisted.
 For certain security considerations, IP address can be stored, if at all they purchase or reorder items, or to know about the geographical location of the visitor.
The following code snippet is used for finding IP address-
$ipAddress=@$REMOTE_ADDR;
echo "<b>IP Address= $ipAddress</b>";
If the register_global is off in php.ini file, then the following script is to be used.
$ipAddress=$_SERVER['REMOTE_ADDR'];

Difference between Reply-to and Return-path in the headers of a mail function.


Reply-to is the address where the email needs to be delivered.
Return-path - specifies the address In case of a failed delivery
$headers .= "Reply-To: info@info.com\r\n";
$headers .= "Return-Path: info@info.com\r\n";


 Reply-to is the id of the user to whom this mail is sent. Where as the Return-path is when the delivery failure occurs, then where to deliver the failure message.

How many Type of encryption function supported in PHP.



  1. crypt(): The crypt() function returns the encrypted string by using DES algorithms.
  2. encrypt(): The encrypt() function encrypts a string using a supplied key.
  3. base64_encode(): This function encrypts the string based on 64 bit encryption.
  4. base64_decode(): This function decrypts the 64 bit encoded string.
  5. md5(): Calculates the MD5 hash of the string using RSA data security algorithm.
  6. Mcrypt_cbc()- Encrypts data in Cipher block chain mode.
  7. Mcrypt_cfb()- Encysrtpts data cipher feedback (CFB) mode
  8. Mcrypt_decrypt()- Decrypts data.
  9. mcrypt_encrypt- Encrypts plaintext with given parameters
  10. mcrypt_generic- encrypts data
  11. mcrypt_get_key_size - Get the key size of the specified cipher
  12. mdecrypt_generic – dectpyts data


PHP Support inheritance?

PHP supports single, multi level inheritance. It will not support multiple inheritance

Is it possible to send HTML mail with php?


Yes, it is possible. The HTML content type to be added to the mail header (as parameter to the function mail() ).
 The following code snippet depicts the possibility.
mail($recipientAddress, $subject, $messageToSend, From : $senderAddress Content-type text/html; charset = iso-8859-1);


‘example@example.com'
// subject
$subject = 'HTML email';

// message
$message = '
<html>
<head>
<title>HTML EMAIL</title>
</head>
<body>
<p>Sample of HTML EMAIL!</p>
</body>
</html>
';
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Joe <joe@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: HTML EMAIL <sample@example.com>' . "\r\n";
$headers .= 'Cc: samplecc@example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>

How to access a COM object from within my PHP page


To access COM object from PHP page, COM class can be made use of.
$obj = new COM("Application.ID")
Example:
<?php
// starting word
$ pad = new COM("pad.application") or die("Unable to instantiate pad ");
echo "Loaded Notepad, version {$ pad ->Version}\n";
//bring it to front
$ pad ->Visible = 1;
//open an empty document
$ pad ->Documents->Add();
//do some weird stuff
$ pad ->Selection->TypeText("This is a test...");
$ pad ->Documents[1]->SaveAs("Sample test.doc");
//closing word
$ pad ->Quit();
//free the object
$ pad = null;
?>
 Create an object of COM. 
  1. - Set the visibility of the file to 1 
  2. - Invoke the function Add() for creation of a document 
  3. - Insert the text into the document 
  4. - Save the file as the destination file 
  5. - Exit the process
The code is furnished here under.
<?
$word=new COM("word.application") or die("Cannot start word application"); 
print "The word version is ($word->Version)\n"; 
$word->visible =1; 
$word->Documents->Add(); 
$word->Selection->Typetext("Sample_text"); 
$word->Documents[1]->SaveAs("samplefile.doc"); 
$word->Quit(); 
?>

Explain how to get the DNS servers of a domain name.


<?
function get_dns($domain)
{
     $end = substr("$domain",-2);
     if($end==uk)
         {$type=uk;}
     else
         {$type=com;}
     if($type==uk)
          {$lookup="whois.nic.uk";}
     else{$lookup="rs.internic.net";}
         $fp = fsockopen( "$lookup", 43, &$errno, &$errstr, 10);
         fputs($fp, "$domain\r\n");
     while(!feof($fp))
     {
         $buf = fgets($fp,128);
         if (ereg( "Domain servers", $buf))
         {
              {$dns = fgets($fp,128);}
              {$dns .= fgets($fp,128);}
          }
          if (ereg( "Name Server:", $buf))
         {
              {$dns = fgets($fp,128);}
              {$dns .= fgets($fp,128);}
              $dns = str_replace( "Name Server:", "", $buf);
              $dns = str_replace( "Server:", "", $dns);
              $dns = trim($dns);
          }
      }
      Return $dns;
}
?>
The process is :
- Include the Net/DNS.php file in the beginning of the script 
- Create the object for DNS resolver by using $ndr = Net_DNS_Resolver() 
- Query the ip address using $ndr->search(“somesite.com”,”A”) and assign to a relevant variable. Ex: $result
- Display the value of $result

Explain how to send large amounts of emails with php.


The mail() function of PHP is quite robust for sending bulk emails. A SMTP server can also be directly used from the script. PHPmailer class can be used for sending emails.

How do you create sub domains using PHP?


A virtual domain can be created by using .htaccess file. Using .htaccess file a sub domain can be created as follows :
http://www.domain.com/?a user --> http://user.domain.com/

What is the difference between using copy() and move() function in php file uploading?

Copy() makes a copy of the file. It returns TRUE on success. It can copy from any source to destination. Move simple Moves the file to destination if the file is valid. While move can move the uploaded file from temp server location to any destination on the server. If filename is a valid upload file, but cannot be moved for some reason, no action will occur.

What is the difference between using copy() and move() function in php file uploading?

Copy() makes a copy of the file. It returns TRUE on success. It can copy from any source to destination. Move simple Moves the file to destination if the file is valid. While move can move the uploaded file from temp server location to any destination on the server. If filename is a valid upload file, but cannot be moved for some reason, no action will occur.

What is the difference between using copy() and move() function in php file uploading?

Copy() makes a copy of the file. It returns TRUE on success. It can copy from any source to destination. Move simple Moves the file to destination if the file is valid. While move can move the uploaded file from temp server location to any destination on the server. If filename is a valid upload file, but cannot be moved for some reason, no action will occur.

How to upload files using PHP?


Files can be uploaded in PHP by using the tag type=”file”. An upload form must have encytype="multipart/form-data" , method also needs to be set to method="post". Also, hidden input MAX_FILE_SIZE before the file input. To restrict the size of files
E.g.
<form enctype="multipart/form-data" action="sampleuplaod.php"
method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000" />

How to upload files using PHP?


Files can be uploaded in PHP by using the tag type=”file”. An upload form must have encytype="multipart/form-data" , method also needs to be set to method="post". Also, hidden input MAX_FILE_SIZE before the file input. To restrict the size of files
E.g.
<form enctype="multipart/form-data" action="sampleuplaod.php"
method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000" />

How do you create sub domains using PHP?

Wild card domains can be used. Sub domains can be created by first creating a sub directory in the /htdocs folder. E.g. /htdocs/mydomain. Then, the host file needs to be modified to define the sub domain. If the sub domains are not configured explicitly, all requests should be thrown to the main domain.  

What is difference between developing website using Java and PHP?


In order to make interactive pages, java uses JSP (Java Server pages). PHP is open source while JSP is not. Libraries are much stronger in Java as compared tp PHP. Huge codes can be managed with ease in Java by making classes.  



  • Both technologies are used for dynamic websites development.
  • PHP is an interpreter based technology where as java is compiler based(usually JSP). 
  • PHP is open source where as JSP is not.
  • Web sites developed in PHP are much more faster compared to Java technology
  • Java is a distributed technology, which means N tier application can be developed, where as PHP is used only for web development.



What is difference between developing website using Java and PHP?


In order to make interactive pages, java uses JSP (Java Server pages). PHP is open source while JSP is not. Libraries are much stronger in Java as compared tp PHP. Huge codes can be managed with ease in Java by making classes.  

What is the difference between Notify URL and Return URL?

Notify URL and Return URL is used in Paypal Payment Gateway integration. Notify URL is used by PayPal to post information about the transaction. Return URL is sued by the browser; A url where the user needs to be redirected on completion of the payment process.   

What is the difference between the functions unlink and unset?


Unlink is a function for file system handling which deletes a file. Unset is used to destroy a variable.  
The function unlink() is to remove a file, where as unset() is used for destroying a variable that was declared earlier.
unset() empties a variable or contents of file.

Explain the ways to retrieve the data in the result set of MySQL using PHP


1. mysql_fetch_row($result):- where $result is the result resource returned from a successful query executed using the mysql_query() function.
Example:
$result = mysql_query(“SELECT * from students);
while($row = mysql_fetch_row($result))
{
      Some statement;
}
2. mysql_fetch_array($result):- Return the current row with both associative and numeric indexes where each column can either be accessed by 0, 1, 2, etc., or the column name.

Example:
$row = mysql_fetch_array($result)
3. mysql_fetch_assoc($result): Return the current row as an associative array, where the name of each column is a key in the array.

Example:
$row = mysql_fetch_assoc($result)
$row[‘column_name’]

What is the difference between mysql_fetch_object and mysql_fetch_array?


Mysql_fetch_object returns the result from the database as objects
while mysql_fetch_array returns result as an array.
This will allow access to the data by the field names.
 E.g.
 using mysql_fetch_object field can be accessed as $result->name and using
mysql_fetch_array field can be accessed as $result->[name]

Describe how PHP Works


PHP stands for Hypertext PreProcessor. It is a general purpose server side scripting language which is particularly suited for web development and can be embedded into HTML. PHP script is always executes on the server. Only the end result is sent to the browser.
The PHP script is embedded in <?php and ?> . This is the instruction to the web server (usually Apache web server) to execute PHP code. The functionality is performed and result of expressions, echo statement etc., is being executed by the web server and the server in turn returns the result of echo statement, interacts with database etc. Using PHP, thousands web pages can be uploaded, being it is dynamic.

What is CAPTCHA?


CAPTCHA is a test to determine if the user using the system (usually a web form) is a human. It identifies this by throwing challenges to users. Depending on the responses the identification can be made. E,g Answering to identification of distorted images. Captcha Creator is a PHP Script that generates Strong Captchas

How can we increase the execution time of a php script?


Default time allowed for the PHP scripts to execute is 30s defined in the php.ini file. The function used is set_time_limit(int seconds). If the value passed is ‘0’, it takes unlimited time. It should be noted that if the default timer is set to 30 sec and 20 sec is specified in set_time_limit(), the script will run for 45 secs.  

E-mail With PHP


PHP uses its inbuilt mail() function to send emails from the script.
Syntax:
mail(to,subject,message,headers,parameters)
Example:
<?php
$to = "sample@ sample.com";
$subject = " sample mail";
$message = “sample email message.";
$from = " sample1@ sample.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
Header is an optional parameter that specifies any CC or BCC. The mail function requires a working email system. SMTP settings needs to be done in the .ini file.

When would you use htmlentities?


HTMLENTITIES disallows users to run malicious code in HTML.
The htmlentities function takes a string and returns the same string with HTML converted into HTML entities.
Syntax:
htmlentities(string,quotestyle,character-set)
String – string to be converted.
Quotestyle- optional parameter that defines how to encode single and double quotes.
Character-set – Optional parameter that specifies the character set.

Creating Your First PHP Cookie.


Cookie in PHP is used to identify a user.
Create a cookie:
Setcookie() can be used for this purpose. It appears before the <html> tag.
setcookie(name, value, expire, path, domain);
Example:
Here, a cookie name user is assigned a value Sample. The cookie expires after an hour
setcookie(“user”, “Sample”, time()+3600);
Retrieve a cookie:
The cookie can be retrieved using PHP $_COOKIE variable
Echo the value:
<?php
        echo $_COOKIE["user"];
?>


A cookie is created by using setCookie() function. This function takes 3 arguments:
- Name – The name of the cookie to be used to retrieve the cookie.
- Value - The value is persisted in the cookie. Usually, user names and last visit date / time are used
- Expiration – The date until which the cookie is alive. After the date the cookie will be expired. If the expiry date is not set, then the cookie is treated as a default cookie and will expire when the browser restarts.
Example code:
<?php
//Set 60 days as the life time for the cookie.
//seconds * minutes * hours * days + current time
$inTwoMonths = 60 * 60 * 24 * 60 + time(); 
setcookie('lastVisit', date("G:i - m/d/y"), $inTwoMonths); 

?>

PHP Functions



  • Any php function starts with function().
  • The name of the function cannot start with a number.
  • A PHP function cannot be overloaded or redefined.
  • PHP functions are case-insensitive.
  • The functions can be either user defined or in built.
  • Any variable declared and defined within a function is restricted within the function only – Unless, accompanied by “global” keyword.


Describe how to create a simple AD rotator script without using database in PHP 


Following are the steps to create a simple AD rotator script without using database in PHP:-
All the ad’s can be collected in one place and be displayed randomly.rand() function can be used for this purpose.

  • In order to NOT use any database, a flat file can be used to store the ad’s.
  • In order to store the Ad’s information (HTML code), a flat file say “ad.txt” can be created.
  • The random number can be stored in a variable 
  • $result_random=rand(1, 100);
  • Conditions can be checked to display the ad’s.
  • if($result_random<=70)
  • {
  •       echo "Display ad1";
  • }


First create a text file with ads.txt extension. Each ad has its unique HTML code. For example :
<a href="http://www.mysite.com">Demo Text Link</a>
Write a function to handle ads. Example :
<?php
// Function to display random ads from a list 
function showRandomAD($ADnumber = 1){
// Loading the ad list into an array
$adList = file('ads.txt');

// Check the total number of ads
$numberOfADs = sizeof($adList);

// Initialize the random generator
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec + ((float) $usec * 100000));

// Initialize the ads counter
$adCount = 0;

// Loop to display the requeste number of ads
while ($adCount++ < $ADnumber) {
// Generate random ad id
$actAD = rand(0, $numberOfADs-1);
// Display the above generated ad from the array
echo $adList[$actAD].'<br/>';
}
}
?>
All the lines from the file is stored in the array.
The function srand() selects the adds randomly from the array.
Create a simple php file and ember the statement <?php showRandomAD(3); ?> to demonstrate the use of rotator ad.

how to work with Permissions in PHP 

Permissions in PHP are very similar to UNIX. Each file has three types of permissions – Read, write and execute. Permissions can be changed using the change mode or CHMOD command. CHMOD is followed by 3 digit number specifying the permission type. CHMOD 777 is for Read, Write and execute.


Permissions are set and unset with the following functions:

-mask(): To set the permissions to the files. Default value is 0777. The first digit is always 0, second digit indicates permission for the owner, third digit indicates the permission for owners group and the fourth digit indicates the permission for all users.
-umask(): To change the permissions to files – mask and 0777.

Thursday, May 9, 2013

What is Dynamic Website?


A dynamic website is one that changes or customizes itself frequently and automatically, based on certain criteria.
Dynamic websites can have two types of dynamic activity:

  •  Code 
  •  Content. 

Dynamic code is invisible or behind the scenes
Dynamic content is visible or fully displayed.

 Dynamic code

The first type is a web page with dynamic code. The code is constructed dynamically on the fly using active programming language instead of plain, static HTML.
A website with dynamic code refers to its construction or how it is built, and more specifically refers to the code used to create a single web page. A dynamic web page is generated on the fly by piecing together certain blocks of code, procedures or routines. A dynamically generated web page would recall various bits of information from a database and put them together in a pre-defined format to present the reader with a coherent page. It interacts with users in a variety of ways including by reading cookies recognizing users' previous history, session variables, server side variables etc., or by using direct interaction (form elements, mouse overs, etc.). A site can display the current state of a dialogue between users, monitor a changing situation, or provide information in some way personalized to the requirements of the individual user.

Dynamic content

The second type is a website with dynamic content displayed in plain view. Variable content is displayed dynamically on the fly based on certain criteria, usually by retrieving content stored in a database.
A website with dynamic content refers to how its messages, text, images and other information are displayed on the web page, and more specifically how its content changes at any given moment. The web page content varies based on certain criteria, either pre-defined rules or variable user input. For example, a website with a database of news articles can use a pre-defined rule which tells it to display all news articles for today's date. This type of dynamic website will automatically show the most current news articles on any given date. Another example of dynamic content is when a retail website with a database of media products allows a user to input a search request for the keyword Beatles. In response, the content of the web page will spontaneously change the way it looked before, and will then display a list of Beatles products like CDs, DVDs and books.



Static Website

A static website is one that has web pages stored on the server in the format that is sent to a client web browser. It is primarily coded in Hypertext Markup Language (HTML).

Simple forms or marketing examples of websites, such as classic website, a five-page website or a brochure website are often static websites, because they present pre-defined, static information to the user. This may include information about a company and its products and services through text, photos, animations, audio/video and interactive menus and navigation.

This type of website usually displays the same information to all visitors. Similar to handing out a printed brochure to customers or clients, a static website will generally provide consistent, standard information for an extended period of time. Although the website owner may make updates periodically, it is a manual
process to edit the text, photos and other content and may require basic website design skills and software.

A static web page may still have dynamic behaviour, provided that this is handled entirely client-side (i.e. within the browser). This may include such features as a JavaScript image zoom feature to display photographs.

What is Website?

A website is a collection of web pages (documents that are accessed through the Internet), such as the one you're looking at now. A web page is what you see on the screen when you type in a web address, click on a link, or put a query in a search engine. A web page can contain any type of information, and can include text, color, graphics, animation and sound.

 A website is hosted on at least one web server, accessible via a network such as the Internet or a private local area network through an Internet address known as a Uniform Resource Locator. All publicly accessible websites collectively constitute the World Wide Web.

Webpages are accessed and transported with the Hypertext Transfer Protocol (HTTP), which may optionally employ encryption (HTTP Secure, HTTPS) to provide security and privacy for the user of the webpage content. The user's application, often a web browser, renders the page content according to its HTML markup instructions onto a display terminal.


 The pages of a website can usually be accessed from a simple Uniform Resource Locator (URL) called the web address.

Using the strpos() function


The strpos() function is used to search for a string or character within a string.

If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE.
Let's see if we can find the string "world" in our string:

<?php
echo strpos("Hello world!","world");
?>

The output of the code above will be:
6

Using the strlen() function


The strlen() function is used to find the length of a string.

Let's find the length of our string "Hello world!":

<?php
echo strlen("Hello world!");
?>

The output of the code above will be:
12

The length of a string is often used in loops or other functions, when it is important to know when the string ends. (i.e. in a loop, we would want to stop the loop after the last character in the string)

PHP Concatenation Operator


The Concatenation Operator

There is only one string operator in PHP.
The concatenation operator (.)  is used to put two string values together.
To concatenate two variables together, use the dot (.) operator:

<?php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2;
?>

The output of the code above will be:
Hello World 1234

PHP String Function


PHP Variables


Variables are used for storing values, such as numbers, strings or function results, so that they can be used many times in a script.

Variables in PHP

  • Variables are used for storing a values, like text strings, numbers or arrays.
  • When a variable is set it can be used over and over again in your script
  • All variables in PHP start with a $ sign symbol.
  • The correct way of setting a variable in PHP:


What is PHP?


PHP is a powerful server-side scripting language for creating dynamic and interactive websites.

PHP is the widely-used, free, and efficient alternative to competitors such as Microsoft's ASP. PHP is perfectly suited for Web development and can be embedded directly into the HTML code.

The PHP syntax is very similar to Perl and C. PHP is often used together with Apache (web server) on various operating systems. It also supports ISAPI and can be used with Microsoft's IIS on Windows.

Tuesday, May 7, 2013

Comparison Operators

Comparison Operators

Here A=10 and B=5 assign
Operator Description Example
== Checks if the value of two operands are equal or not, if yes then condition becomes true. (A == B) is not true.
!= Checks if the value of two operands ar equal or not, if values are not equal then condition becomes true. (A != B) is true.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. (A < B) is true.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. (A < B) is false.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. (A >= B) is true.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. (A <= B) is false.
Get More Knoweledge You Join Sharda Technologies

What is PHP?


The PHP Hypertext Pre-processor (PHP) is a programming language that allows web
developers to create dynamic content that interacts with databases.

PHP is basically used for developing web based software applications.

Get More Knoweledge You Join Sharda Technologies