Pages



Definition and Usage

The array_diff_assoc() function compares the keys and values of two (or more) arrays, and returns the differences.
This function compares the keys and values of two (or more) arrays, and return an array that contains the entries from array1 that are not present in array2 or array3, etc.

Syntax

array_diff_assoc(array1,array2,array3...);
 
Example :

$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("a"=>"red","b"=>"green","c"=>"blue");

$result=array_diff_assoc($a1,$a2);
print_r($result);
?>
 



OR :


$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("a"=>"red","f"=>"green","g"=>"blue");
$a3=array("h"=>"red","b"=>"green","g"=>"blue");

$result=array_diff_assoc($a1,$a2,$a3);
print_r($result);
?>

 
+PHP Development Outsourcing +PHP Developers +PHP Tutorials +PHP Programming +My PHP Developers +My PHP Developers


Example :

<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"green","g"=>"blue");

$result=array_diff($a1,$a2);
print_r($result);
?>
 


OR


<?php
$a1=array("a"=>"red","b"=>"green","c"=>"blue","d"=>"yellow");
$a2=array("e"=>"red","f"=>"black","g"=>"purple");
$a3=array("a"=>"red","b"=>"black","h"=>"yellow");

$result=array_diff($a1,$a2,$a3);
print_r($result);
?>

Syntax

array_diff(array1,array2,array3...);

+PHP Development Outsourcing +PHP Developers +PHP Tutorials +PHP Programming +My PHP Developers +My PHP Developers


Example :

<?php
$a=array("A","Cat","Dog","A","Dog");
print_r(array_count_values($a));
?>  


Syntax

 array_count_values(array)

+PHP Development Outsourcing +PHP Developers +PHP Tutorials +PHP Programming +My PHP Developers +My PHP Developers

 
Example :


<?php
$fname=array("Peter","Ben","Joe");
$age=array("35","37","43");

$c=array_combine($fname,$age);
print_r($c);
?>

Syntax

array_combine(namearray1,nameofarray2);

+PHP Development Outsourcing +PHP Developers +PHP Tutorials +PHP Programming +My PHP Developers +My PHP Developers

Description:

This method returns the tangent of a number. The tan method returns a numeric value that represents the tangent of the angle.

Syntax:

Math.tan( x ) ;
Here is the detail of parameters:
  • x: A number representing an angle in radians.

Return Value:

Returns the tangent of a number.

Example:

<html>
<head>
<title>JavaScript Math tan() Method</title>
</head>
<body>
<script type="text/javascript">

var value = Math.tan( -30 );
document.write("First Test Value : " + value ); 
  
var value = Math.tan( 90 );
document.write("<br />Second Test Value : " + value ); 

var value = Math.tan( 45 );
document.write("<br />Third Test Value : " + value ); 

var value = Math.tan( Math.PI/180 );
document.write("<br />Fourth Test Value : " + value ); 
</script>
</body>
</html>
This will produce following result:
First Test Value : 1
Second Test Value : 21
Third Test Value : 20
Fourth Test Value : -20 
 
+JavaScript +JavaScript Frameworks Links +Javascript Development 
+JavaScript's and More, Software and Marketing +JavascriptU +JavaScriptOn 
+Javascript Problems +JavaScriptOn 
 +javaScript is a creek in West Virginia in the summe  
+enJineS +JavascriptU +Javascript Tutor   

CSS3 Border Properties

Property Description CSS
border-image A shorthand property for setting all the border-image-* properties 3
border-radius A shorthand property for setting all the four border-*-radius properties 3
box-shadow Attaches one or more drop-shadows to the box


To clearly illustrate how easy it is to access information from a database using Ajax, we are going to build MySQL queries on the fly and display the results on "ajax.html". But before we proceed, lets do ground work. Create a table using the following command.

NOTE: We are asuing you have sufficient privilege to perform following MySQL operations

CREATE TABLE `ajax_example` (
  `name` varchar(50) NOT NULL,
  `age` int(11) NOT NULL,
  `sex` varchar(1) NOT NULL,
  `wpm` int(11) NOT NULL,
  PRIMARY KEY  (`name`)
) 
 
Now dump the following data into this table using the following SQL statements
INSERT INTO `ajax_example` VALUES ('Jerry', 120, 'm', 20);
INSERT INTO `ajax_example` VALUES ('Regis', 75, 'm', 44);
INSERT INTO `ajax_example` VALUES ('Frank', 45, 'm', 87);
INSERT INTO `ajax_example` VALUES ('Jill', 22, 'f', 72);
INSERT INTO `ajax_example` VALUES ('Tracy', 27, 'f', 0);
INSERT INTO `ajax_example` VALUES ('Julie', 35, 'f', 90);

Client Side HTML file

Now lets have our client side HTML file which is ajax.html and it will have following code
<html>
<body>
<script language="javascript" type="text/javascript">
<!-- 
//Browser Support Code
function ajaxFunction(){
 var ajaxRequest;  // The variable that makes Ajax possible!
 
 try{
   // Opera 8.0+, Firefox, Safari
   ajaxRequest = new XMLHttpRequest();
 }catch (e){
   // Internet Explorer Browsers
   try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
   }catch (e) {
      try{
         ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }catch (e){
         // Something went wrong
         alert("Your browser broke!");
         return false;
      }
   }
 }
 // Create a function that will receive data 
 // sent from the server and will update
 // div section in the same page.
 ajaxRequest.onreadystatechange = function(){
   if(ajaxRequest.readyState == 4){
      var ajaxDisplay = document.getElementById('ajaxDiv');
      ajaxDisplay.innerHTML = ajaxRequest.responseText;
   }
 }
 // Now get the value from user and pass it to
 // server script.
 var age = document.getElementById('age').value;
 var wpm = document.getElementById('wpm').value;
 var sex = document.getElementById('sex').value;
 var queryString = "?age=" + age ;
 queryString +=  "&wpm=" + wpm + "&sex=" + sex;
 ajaxRequest.open("GET", "ajax-example.php" + 
                              queryString, true);
 ajaxRequest.send(null); 
}
//-->
</script>
<form name='myForm'>
Max Age: <input type='text' id='age' /> <br />
Max WPM: <input type='text' id='wpm' />
<br />
Sex: <select id='sex'>
<option value="m">m</option>
<option value="f">f</option>
</select>
<input type='button' onclick='ajaxFunction()' 
                              value='Query MySQL'/>
</form>
<div id='ajaxDiv'>Your result will display here</div>
</body>
</html> 
 

Server Side PHP file

So now your client side script is ready. Now we have to write our server side script which will fetch age, wpm and sex from the database and will send it back to the client. Put the following code into "ajax-example.php" file

<?php $dbhost = "localhost"; $dbuser = "dbusername"; $dbpass = "dbpassword"; $dbname = "dbname"; //Connect to MySQL Server mysql_connect($dbhost, $dbuser, $dbpass); //Select Database mysql_select_db($dbname) or die(mysql_error()); // Retrieve data from Query String $age = $_GET['age']; $sex = $_GET['sex']; $wpm = $_GET['wpm']; // Escape User Input to help prevent SQL Injection $age = mysql_real_escape_string($age); $sex = mysql_real_escape_string($sex); $wpm = mysql_real_escape_string($wpm); //build query $query = "SELECT * FROM ajax_example WHERE sex = '$sex'"; if(is_numeric($age)) $query .= " AND age <= $age"; if(is_numeric($wpm)) $query .= " AND wpm <= $wpm"; //Execute query $qry_result = mysql_query($query) or die(mysql_error()); //Build Result String $display_string = "<table>"; $display_string .= "<tr>"; $display_string .= "<th>Name</th>"; $display_string .= "<th>Age</th>"; $display_string .= "<th>Sex</th>"; $display_string .= "<th>WPM</th>"; $display_string .= "</tr>"; // Insert a new row in the table for each person returned while($row = mysql_fetch_array($qry_result)){ $display_string .= "<tr>"; $display_string .= "<td>$row[name]</td>"; $display_string .= "<td>$row[age]</td>"; $display_string .= "<td>$row[sex]</td>"; $display_string .= "<td>$row[wpm]</td>"; $display_string .= "</tr>"; } echo "Query: " . $query . "<br />"; $display_string .= "</table>"; echo $display_string; ?>
 
+PHP Developers  +PHP Tutorials +PHP Programming  +PHP Development Outsourcing 
PHP provides a large number of predefined variables to any script which it runs.PHP provides an additional set of predefined arrays containing variables from the web server the environment, and user input. These new arrays are called superglobals:
All the following variables are automatically available in every scope.


PHP Superglobals: 

VariableDescription
$GLOBALS Contains a reference to every variable which is currently available within the global scope of the script. The keys of this array are the names of the global variables.
$_SERVER This is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these. See next section for a complete list of all the SERVER variables.
$_GET An associative array of variables passed to the current script via the HTTP GET method.
$_POST An associative array of variables passed to the current script via the HTTP POST method.
$_FILES An associative array of items uploaded to the current script via the HTTP POST method.
$_REQUEST An associative array consisting of the contents of $_GET, $_POST, and $_COOKIE.
$_COOKIE An associative array of variables passed to the current script via HTTP cookies.
$_SESSION An associative array containing session variables available to the current script.
$_PHP_SELF A string containing PHP script file name in which it is called.
$php_errormsg $php_errormsg is a variable containing the text of the last error message generated by PHP.

Server variables: $_SERVER

$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these.
VariableDescription
$_SERVER['PHP_SELF'] The filename of the currently executing script, relative to the document root
$_SERVER['argv'] Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string.
$_SERVER['argc'] Contains the number of command line parameters passed to the script if run on the command line.
$_SERVER['GATEWAY_INTERFACE'] What revision of the CGI specification the server is using; i.e. 'CGI/1.1'.
$_SERVER['SERVER_ADDR'] The IP address of the server under which the current script is executing.
$_SERVER['SERVER_NAME'] The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.
$_SERVER['SERVER_SOFTWARE'] Server identification string, given in the headers when responding to requests.
$_SERVER['SERVER_PROTOCOL'] Name and revision of the information protocol via which the page was requested; i.e. 'HTTP/1.0';
$_SERVER['REQUEST_METHOD'] Which request method was used to access the page; i.e. 'GET', 'HEAD', 'POST', 'PUT'.
$_SERVER['REQUEST_TIME'] The timestamp of the start of the request. Available since PHP 5.1.0.
$_SERVER['QUERY_STRING'] The query string, if any, via which the page was accessed.
$_SERVER['DOCUMENT_ROOT'] The document root directory under which the current script is executing, as defined in the server's configuration file.
$_SERVER['HTTP_ACCEPT'] Contents of the Accept: header from the current request, if there is one.
$_SERVER['HTTP_ACCEPT_CHARSET'] Contents of the Accept-Charset: header from the current request, if there is one. Example: 'iso-8859-1,*,utf-8'.
$_SERVER['HTTP_ACCEPT_ENCODING'] Contents of the Accept-Encoding: header from the current request, if there is one. Example: 'gzip'.
$_SERVER['HTTP_ACCEPT_LANGUAGE'] Contents of the Accept-Language: header from the current request, if there is one. Example: 'en'.
$_SERVER['HTTP_CONNECTION'] Contents of the Connection: header from the current request, if there is one. Example: 'Keep-Alive'.
$_SERVER['HTTP_HOST'] Contents of the Host: header from the current request, if there is one.
$_SERVER['HTTP_REFERER'] The address of the page (if any) which referred the user agent to the current page.
$_SERVER['HTTP_USER_AGENT'] This is a string denoting the user agent being which is accessing the page. A typical example is: Mozilla/4.5 [en] (X11; U; Linux 2.2.9 i586).
$_SERVER['HTTPS'] Set to a non-empty value if the script was queried through the HTTPS protocol.
$_SERVER['REMOTE_ADDR'] The IP address from which the user is viewing the current page.
$_SERVER['REMOTE_HOST'] The Host name from which the user is viewing the current page. The reverse dns lookup is based off the REMOTE_ADDR of the user.
$_SERVER['REMOTE_PORT'] The port being used on the user's machine to communicate with the web server.
$_SERVER['SCRIPT_FILENAME'] The absolute pathname of the currently executing script.
$_SERVER['SERVER_ADMIN'] The value given to the SERVER_ADMIN (for Apache) directive in the web server configuration file.
$_SERVER['SERVER_PORT'] The port on the server machine being used by the web server for communication. For default setups, this will be '80'.
$_SERVER['SERVER_SIGNATURE'] String containing the server version and virtual host name which are added to server-generated pages, if enabled.
$_SERVER['PATH_TRANSLATED'] Filesystem based path to the current script.
$_SERVER['SCRIPT_NAME'] Contains the current script's path. This is useful for pages which need to point to themselves.
$_SERVER['REQUEST_URI'] The URI which was given in order to access this page; for instance, '/index.html'.
$_SERVER['PHP_AUTH_DIGEST'] When running under Apache as module doing Digest HTTP authentication this variable is set to the 'Authorization' header sent by the client.
$_SERVER['PHP_AUTH_USER'] When running under Apache or IIS (ISAPI on PHP 5) as module doing HTTP authentication this variable is set to the username provided by the user.
$_SERVER['PHP_AUTH_PW'] When running under Apache or IIS (ISAPI on PHP 5) as module doing HTTP authentication this variable is set to the password provided by the user.
$_SERVER['AUTH_TYPE'] When running under Apache as module doing HTTP authenticated this variable is set to the authentication type.
Example :

 




 In HTML File 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<form action="cases.php" method="post">

Type any word<input type="text" name="word"/>

<input name="submit" type="submit" value="Length"/>

</form>

</body>

</html>


Note : Enter the words in Text box "Haider Ali"





In Php File:


<?php

$word=$_POST['word'];

 echo trim($word,"Hai");


?>


Example Download....!

+PHP Development Outsourcing +PHP Developers +PHP Tutorials +PHP Programming +My PHP Developers +My PHP Developers
Example :

 




 In HTML File 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<form action="cases.php" method="post">

Type any word<input type="text" name="word"/>

<input name="submit" type="submit" value="Length"/>

</form>

</body>

</html>


In Php File:


<?php

$word=$_POST['word'];

 echo strlen($word);

?>


Example Download....!

+PHP Development Outsourcing +PHP Developers +PHP Tutorials +PHP Programming +My PHP Developers +My PHP Developers 

Example :

 




 In HTML File 

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<form action="cases.php" method="post">

Type any word<input type="text" name="word"/>

<input name="submit" type="submit" value="lowercase"/>

</form>

</body>

</html>


In Php File:


<?php

$word=$_POST['word'];

 echo ucwords($word);

?>


Example Download....!

+PHP Development Outsourcing +PHP Developers  +PHP Tutorials +PHP Programming 
+My PHP Developers +phptutorial rs +phptutorial care +phptutorail +PHPtutorials 
+PHPTutorials +PHPtutorials +phptutorail 
Example :

 In HTML File 


<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<form action="cases.php" method="post">

Type any word<input type="text" name="word"/>

<input name="submit" type="submit" value="lowercase"/>

</form>

</body>

</html>


In Php File:


<?php

$word=$_POST['word'];

 echo ucfirst($word);

?>


Example Download....!

Upper Case Using PHP


Example :

 In HTML File 


<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<form action="cases.php" method="post">

Type any word<input type="text" name="word"/>

<input name="submit" type="submit" value="lowercase"/>

</form>

</body>

</html>


In Php File:

<?php

$word=$_POST['word'];

 echo strtoupper($word);

?>



Example Download....!


PHP also allows you to work with folders on the server. We will not go through all the different possibilities - only show an example. Again, see the documentation for more information.


Example :

 <html>
 <head>
 <title>FileSystemObject</title>
 </head>
 <body>

 <?php
   
 // Opens the folder
 $folder = opendir("../../tutorials/php/");

 // Loop trough all files in the folder
 while (($entry = readdir($folder)) != "") {
    echo $entry . "<br />";
 }

 // Close folder
 $folder = closedir($folder);

 ?>

 </body>

 </html>
In the previous lesson, we learned how to use PHP to access the server's filesystem. In this lesson, we will use that information to read from an ordinary text file.
Text files can be extremely useful for storing various kinds of data. They are not quite as flexible as real databases, but text files typically don't require as much memory. Moreover, text files are a plain and simple format that works on most systems.

Open the text file

We use the fopen function to open a text file. The syntax is as follows:

fopen(filename, mode)
 
filename
Name of the file to be opened.
mode
Mode can be set to "r" (reading), "w" (writing) or "a" (appending). In this lesson, we will only read from a file and, therefore, use "r". In the next lesson, we will learn to write and append text to a file.

First, let's try to open unitednations.txt:

 <?php

 // Open the text file
 $f = fopen("unitednations.txt", "r");

 // Close the text file
 fclose($f);

 ?>

Example 1: Read a line from the text file

 

<html>

 <head>
 <title>Reading from text files</title>
 </head>
 <body>

 <?php

 $f = fopen("unitednations.txt", "r");

 // Read line from the text file and write the contents to the client
 echo fgets($f); 

 fclose($f);

 ?>

 </body>
 </html> 
 

Example 2: Read all lines from the text file

  <html>

 <head>
 <title>Reading from text files</title>
 </head>
 <body>

 <?php

 $f = fopen("unitednations.txt", "r");

 // Read line by line until end of file
 while(!feof($f)) { 
     echo fgets($f) . "<br />";
 }

 fclose($f);

 ?>

 </body>
 </html>
 


 
 

Open the text file for writing

In the same way as when reading from a text file, the fopen function is used for writing, but this time we set the mode to "w" (writing) or "a" (appending).
The difference between writing and appending is where the 'cursor' is located - either at the beginning or at the end of the text file.
The examples in this lesson use an empty text file called textfile.txt. But you can also create your own text file if you like.
First, let us try to open the text file for writing:

 

 <?php

 // Open the text file
 $f = fopen("textfile.txt", "w");

 // Close the text file
 fclose($f);

 ?>
 

Example 1: Write a line to the text file

 

<html>

 <head>
 <title>Writing to a text file</title>
 </head>
 <body>

 <?php

 // Open the text file
 $f = fopen("textfile.txt", "w");

 // Write text line
 fwrite($f, "PHP is fun!"); 

 // Close the text file
 fclose($f);

 // Open file for reading, and read the line
 $f = fopen("textfile.txt", "r");
 echo fgets($f); 

 fclose($f);

 ?>

 </body>
 </html> 
 

Example 2: Adding a text block to a text file

 

<html>
 <head>
 <title>Write to a text file</title>
 </head>
 <body>

 <h1>Adding a text block to a text file:</h1>
 <form action="myfile.php" method='post'>
 <textarea name='textblock'></textarea>
 <input type='submit' value='Add text'>
 </form>

 <?php

 // Open the text file
 $f = fopen("textfile.txt", "w");

 // Write text
 fwrite($f, $_POST["textblock"]); 

 // Close the text file
 fclose($f);

 // Open file for reading, and read the line
 $f = fopen("textfile.txt", "r");

 // Read text
 echo fgets($f); 
 fclose($f);

 ?>
 
 </body>

 </html>

 

 

 

 
With PHP, you can access the server's filesystem. This allows you to manipulate folders and text files in PHP scripts.
For example, you can use PHP to read or write a text file. Or you can list all files in a specified folder. There are many possibilities and PHP can save you lots of tedious work.
Here, we'll look at how you can use PHP to work with folders and files. The goal is to give you a quick overview. In the next lessons, we will look more closely at the different possibilities. We will not go through all the different possibilities. Again, see the documentation for a complete listing.

Example 

<html>

 <head>
 <title>Filesystem</title>
 </head>
 <body>
  
 <?php
   
 // Find and write properties
 echo "<h1>file: lesson14.php</h1>";
 echo "<p>Was last edited: " . date("r", filemtime("lesson14.php")); 
 echo "<p>Was last opened: " . date("r", fileatime("lesson14.php")); 
 echo "<p>Size: " . filesize("lesson14.php") . " bytes";
 
 ?>

 </body>
 </html>
 


Example :

 In HTML File 

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Untitled Document</title>

</head>

<body>

<form action="cases.php" method="post">

Type any word<input type="text" name="word"/>

<input name="submit" type="submit" value="lowercase"/>

</form>

</body>

</html>


In Php File:

<?php

$word=$_POST['word'];

 echo strtolower($word);

?>



Example Download....!

The DELETE statement is used to delete records in a table.

Delete Data In a Database

The DELETE FROM statement is used to delete records from a database table.

Syntax

DELETE FROM table_name
WHERE some_column = some_value

Note: Notice the WHERE clause in the DELETE syntax. The WHERE clause specifies which record or records that should be deleted. If you omit the WHERE clause, all records will be deleted!
To learn more about SQL, please visit our SQL tutorial.
To get PHP to execute the statement above we must use the mysqli_query() function. This function is used to send a query or command to a MySQL connection.

Example

Look at the following "Persons" table:

FirstNameLastNameAge
PeterGriffin35
GlennQuagmire33

The following example deletes all the records in the "Persons" table where LastName='Griffin':

<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

mysqli_query($con,"DELETE FROM Persons WHERE LastName='Griffin'");

mysqli_close($con);
?>
After the deletion, the table will look like this:



FirstNameLastNameAge
GlennQuagmire33


Example Download....! 






The UPDATE statement is used to modify data in a table.

Update Data In a Database

The UPDATE statement is used to update existing records in a table.

Syntax

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

Note: Notice the WHERE clause in the UPDATE syntax. The WHERE clause specifies which record or records that should be updated. If you omit the WHERE clause, all records will be updated!


To learn more about SQL, please visit our SQL tutorial.
To get PHP to execute the statement above we must use the mysqli_query() function. This function is used to send a query or command to a MySQL connection.

Example

Earlier in the tutorial we created a table named "Persons". Here is how it looks:

FirstName LastName Age
Peter Griffin 35
Glenn Quagmire 33
The following example updates some data in the "Persons" table:
<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

mysqli_query($con,"UPDATE Persons SET Age=36
WHERE FirstName='Peter' AND LastName='Griffin'");

mysqli_close($con);
?> 
 
After the update, the "Persons" table will look like this:

FirstName LastName Age
Peter Griffin 36
Glenn Quagmire 33
Flag Counter
| Copyright © 2013 Remote Tutor