Find next Monday date in PHP
<?php
$day = date('d');
$month = date('m');
$year = date('Y');
$nextMonday = date("Y, m, d",strtotime('next Monday',mktime(0,0,0,$month,$day,$year)));
echo $nextMonday;
?>Generate random numbers in PHP
There are several ways of generating random numbers in PHP. We can use a rand() function which takes two parameters(optional) to generate random numbers. But there is one more function which is more efficient mt_rand() which also takes two optional parameters, minimum and maximum value. I am going to generate some random numbers using mt_rand() function.
<?php
//Generating 10 random numbers
for($i = 0; $i < 10; $i++)
{
//Generates random number between 0 and 50
echo mt_rand(0, 50) . '---';
}
?>
Here is the output of the above code:
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
Subscribe to:
Posts (Atom)













