Read XML file using PHP
Reading XML file in PHP is as easy as copy-paste. We can read an XML file using simplexml_load_file() function which takes XML filename as a parameter:
simplexml_load_file($filename);
Let's read an XML file containing song list:
Now the PHP:
?php
$filename = "sample.xml";
$xml = simplexml_load_file($filename);
?>
Now you access any tag in the XML using the variable $xml.
Let's see how it works:
Now let's what it did for us:
You can also access the attributes like this:
And here is the output:
Hope this tutorial will be helpful to you...
simplexml_load_file($filename);
Let's read an XML file containing song list:
Now the PHP:
?php
$filename = "sample.xml";
$xml = simplexml_load_file($filename);
?>
Now you access any tag in the XML using the variable $xml.
Let's see how it works:
Now let's what it did for us:
You can also access the attributes like this:
which will look like this:
And in the end if you want to read the whole XML, then abviously loop will be used, here is the code:
And here is the output:
Hope this tutorial will be helpful to you...
Styling HTML5 Validation
To change the style of the validation message bubble, four div elements with pseudo-classes are used:
::-webkit-validation-bubble
::-webkit-validation-bubble-arrow-clipper
::-webkit-validation-bubble-arrow
::-webkit-validation-bubble-message
You can clearly see the change in the validation message bubble
You can learn more about this styling at WebKit wiki.
::-webkit-validation-bubble
::-webkit-validation-bubble-arrow-clipper
::-webkit-validation-bubble-arrow
::-webkit-validation-bubble-message
You can clearly see the change in the validation message bubble
![]() |
| Before Styling |
![]() |
| After Styling |
Let's add some style in the validated input field I've created here:
CSS:
::-webkit-validation-bubble-arrow
{
border:2px solid #F00;
background:#FD8484;
-webkit-box-shadow:none;
}
::-webkit-validation-bubble-message
{
position: relative;
color:#F00;
background:#FD8484;
border:2px solid #F00;
-webkit-box-shadow: 2px 2px 3px rgba(0,0,0,0.333);
}
This is what it will give:
![]() |
| After Styling |
You can learn more about this styling at WebKit wiki.
HTML5 Form Validation
To validate a form in HTML5, you don't need to write tons of code, it is as easy as copy and paste in HTML5. All you have to do is this:
The 'required' attribute :
To make the field required for the user, just add a 'required' attribute in any input field:
Your Name: <input type="text" name="name" required>
which gives you
Other input types :
There are many other input types in HTML5 which gives you full control to validate you forms, some of the commonly used are given below:
1. Email :
The input field with email attribute accepts only email addresses:
Your Email: <input type="email" name="email">
<input type="submit" name="submit" value="Submit">
2. Number :
The number attribute gives the user numbers to select, for example Age.
Enter Age: <input type="number" name="age">
You can define the 'min' and 'max' attributes to constrain the field:
Enter Age: <input type="number" name="age" min="18" max="50">
3. Url :
Similarly, there are other attributes by which you can validate your form:
The 'required' attribute :
To make the field required for the user, just add a 'required' attribute in any input field:
Your Name: <input type="text" name="name" required>
which gives you
![]() |
| The 'required' attribute |
There are many other input types in HTML5 which gives you full control to validate you forms, some of the commonly used are given below:
1. Email :
The input field with email attribute accepts only email addresses:
Your Email: <input type="email" name="email">
<input type="submit" name="submit" value="Submit">
![]() |
| Email Validation |
2. Number :
The number attribute gives the user numbers to select, for example Age.
Enter Age: <input type="number" name="age">
You can define the 'min' and 'max' attributes to constrain the field:
Enter Age: <input type="number" name="age" min="18" max="50">
![]() |
| Number Attribute |
3. Url :
The url attribute let you to take urls from user:
Enter URL: <input type="url" name="website">
![]() |
| URL Attribute |
Similarly, there are other attributes by which you can validate your form:
- search
- date
- month
- week
- tel
- time
- color
Now the question is can we style the validation bubble? And surely the answer is yes. The next tutorial shows you how to give style to the validation bubble.
How to give shadow in css
To give shadow, box-shadow property is used.
Here is the general syntax to use this property:
box-shadow:h-value v-value blur spread color inset;
Let's make a rectangle with some shadow effect:
CSS:
HTML
<div class="shadow"></div>
Here is what we create:
Here is the general syntax to use this property:
box-shadow:h-value v-value blur spread color inset;
Let's make a rectangle with some shadow effect:
CSS:
.shadow
{
width:250px;
height:250px;
background-color:#666;
box-shadow:10px 10px 10px 5px #333;
-webkit-box-radius:10px 10px 10px 5px #333;
-moz-box-shadow:10px 10px 10px 5px #333;
}
<div class="shadow"></div>
Here is what we create:
How to select the largest value in MySQL?
To return the largest value from a column, MAX() function is used.
Here is the syntax:
Example:
Look at the following "Orders" table. Now we want to find the largest value of the "OrderPrice" column.
Here is the syntax:
SELECT MAX(column_name) FROM table_name
Example:
Look at the following "Orders" table. Now we want to find the largest value of the "OrderPrice" column.
| OrderId | OrderDate | OrderPrice |
|---|---|---|
| 1 | 2010/11/12 | 1000 |
| 2 | 2010/10/23 | 1600 |
| 3 | 2010/09/02 | 700 |
| 4 | 2010/09/03 | 300 |
| 5 | 2010/08/30 | 2000 |
| 6 | 2010/10/04 | 100 |
This can be done by using this statement:
SELECT MAX(OrderPrice) FROM Orders
Result:
2000
How to connect to MySQL database through PHP?
In PHP, we can connect to the database with the mysql_connect() function.
<?php
mysql_connect("server","user","password") or die(mysql_error());
?>
where "server" is the host name (usually 'localhost'),
"user" and "password" is the username and password for that database respectively.
The "or die(mysql..." code displays an error message in your browser if --you've probably guessed it -- there is an error in processing the connection! Double-check your username, password, or server if you receive this error.
<?php
mysql_connect("server","user","password") or die(mysql_error());
?>
where "server" is the host name (usually 'localhost'),
"user" and "password" is the username and password for that database respectively.
The "or die(mysql..." code displays an error message in your browser if --you've probably guessed it -- there is an error in processing the connection! Double-check your username, password, or server if you receive this error.
How to create Navigation Bar using CSS?
![]() |
| Navigation Bar using CSS Live Demo HTML Part: The HTML part is very simple, the structure is a <ul> list with a <li> element for each link in the navigation bar: <ul> <li><a href="#">Home</a></li> <li><a href="#">Services</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> CSS Part: Copy the css code and paste in the <header> section of your webpage: <style> ul { list-style:none; padding:0px; margin:0px; } li { float:left; } a:link, a:visited { display:block; width:150px; text-align:center; font-family:Tahoma, Verdana; color:#333333; text-decoration:none; padding:6px; font-weight:bold; background-color:#66CCFF; } a:hover { background-color:#6699CC; } </style> |
How to redirect in PHP?
In PHP, header() function is used redirect from one page to another:
<?php
header("Location:http://www.webistuffs.blogspot.com");
?>
<?php
header("Location:http://www.webistuffs.blogspot.com");
?>
How to create a Contact Form with Validation in Dreamweaver?
First of all, select "FORM" from the insert tab as shown in figure(1).
![]() |
| figure(1) |
This will create a form indicated with red dots. [figure(2)]
![]() |
| figure(2) |
Now add a text field like in figure(3).
![]() |
| figure(3) |
Give it a label of Name:
![]() |
| figure(4) |
This will create a text box with label "Name:" [figure(5)]
![]() |
| figure(5) |
Simply repeat a step to create another text field with label "E-mail:" [figure(6)]
![]() |
| figure(6) |
![]() |
| figure(7) |
Now add buttons through which we can submit or reset our form. Select Button
and press OK.
![]() |
| figure(8) |
Now you can see in the below picture that couple of buttons are added to submit and reset our form. But both have the same value i.e. Submit and both will submit the form but we want one to submit and other one to reset the form. For this change the value of the second button as shown in figure(9) and its action to Reset Form.
![]() |
| figure(9) |
Now we have completed our work. The form will look like this:
![]() |
| figure(10) |
Now to validate our form, go to Tag Inspector and open Behaviors tab and click on the plus sign. [figure(11)]
![]() |
| figure(11) |
Select "Validate Form"
![]() |
| figure(12) |
Validate the form as your requirement.
![]() |
| figure(13) |
![]() |
| figure(14) |
Hope its helpful...
Redirection Through Javascript
To create a Javascript redirection, place the following code in the <head> section of your webpage:
<script type="text/javascript"> <!-- window.location = "http://www.webistuffs.blogspot.com" //--> </script>
How to Add favicon icon in the Website?
- Create a 16 pixel wide by 16 pixel high favicon.bmp file in a Program like MS-Paint, Adobe Photoshop , or Jasc's Paint Shop Pro , then use a program (such as the free IrFanView app [for Windows]) to reduce the colors to 16 colors [Image -> Decrease Color Depth], and then 'save as...' to a Windows Icon Format (favicon.ico).
- Upload the image (favicon.ico) to the root section of you site.
- Add the following code to the <head> section of your webpage:
<link rel="icon" type="image/ico" href="favicon.ico" />
What is PHP?
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
Nice, but what does that mean? An example:
*************************************************************
************************************************************
Instead of lots of commands to output HTML (as seen in C or Perl), PHP pages contain HTML with embedded code that does "something" (in this case, output "Hi, I'm a PHP script!"). The PHP code is enclosed in special start and end processing instructions
Nice, but what does that mean? An example:
*************************************************************
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Example</title>
</head>
<body>
<?php
echo "Hi, I'm a PHP script!";
?>
</body>
</html>************************************************************
Instead of lots of commands to output HTML (as seen in C or Perl), PHP pages contain HTML with embedded code that does "something" (in this case, output "Hi, I'm a PHP script!"). The PHP code is enclosed in special start and end processing instructions
<?php and ?> that allow you to jump into and out of "PHP mode".
Subscribe to:
Posts (Atom)



























