PHP scripts and programs for Beginner to Master php programs, php ready to use scripts & functions, css tutorials, html, javascripts, ajax examples for Beginner to Master
Sabtu, 26 Desember 2009
The new version 3.0.4 of PHP AdminPanel Pro was released.
The new version 3.0.4 of PHP AdminPanel Pro is available now for downloading. There are many bugs fixed and also Many NEW additions and improvements. This version requires full re-installation, if you work with one of previous. All recent changes can be viewed here.
Check here our Tour and Screenshots!
And new DataGrid Pages Wizard Online DEMO
The Features:
• One-Year FREE Updates
•
Jumat, 18 Desember 2009
How to Get value stored in Cookie in php ?
Now you have learnt to set a cookie in php. Now the next thing is to retrieve the value stored in cookie.
With the following code you can retrieve the value stored in cookie.
To get the value stored in cookie we are using global variable $_COOKIE.
Here we are getting the value stored in cookie to the variable $mycookie.
Here is full code to check & print the value of the cookie.
With the following code you can retrieve the value stored in cookie.
To get the value stored in cookie we are using global variable $_COOKIE.
Here we are getting the value stored in cookie to the variable $mycookie.
Here is full code to check & print the value of the cookie.
Kamis, 17 Desember 2009
Error while creating a cookie - Warning: Cannot modify header information...
Hi,
This error comes when some data is sent to the browser before setting the cookie.
so the above code will give error.
So you should do following thing.
Are you getting this kind of error when creating a cookie or setting a cookie -
Warning: Cannot modify header information - headers already sent by (output started at e:\wamp\www\mysite\test.php:3) in e:\wamp\www\mysite\test.php on line 4
This error comes when some data is sent to the browser before setting the cookie.
So setcookie or setrawcookie function should be the first to be called means,
setcookie or setrawcookie function should be the first line on your page.
So if you use code like this
so the above code will give error.
So you should do following thing.
How to Set a Raw Cookie in php ?
You might be searching for how to set a raw cookie in php. So here is a simple example which shows how to set a raw cookie.
To set a cookie use the function "setrawcookie"
setrawcookie() is exactly the same as setcookie() except that the cookie value will not be automatically urlencoded when sent to the browser.
This function accepts different number of arguments or parameters as setcookie. You can see the php reference manual of setcookie function here for more details.
In the following example we are passing 3 parameters
1) cookie name - its the name by which cookie will be identified.
2) cookie value - its the value stored in cookie.
3) expiration time - the time till the cookie will be available, after that it will be destroyed.
You can set the cookie by using above function.
more details can be found here.
To set a cookie use the function "setrawcookie"
setrawcookie() is exactly the same as setcookie() except that the cookie value will not be automatically urlencoded when sent to the browser.
This function accepts different number of arguments or parameters as setcookie. You can see the php reference manual of setcookie function here for more details.
In the following example we are passing 3 parameters
1) cookie name - its the name by which cookie will be identified.
2) cookie value - its the value stored in cookie.
3) expiration time - the time till the cookie will be available, after that it will be destroyed.
You can set the cookie by using above function.
more details can be found here.
How to Set a urlencoded Cookie in PHP ?
You might be searching for how to set a cookie in php. So here is a simple example which shows how to set a cookie.
To set a cookie use the function "setcookie"
Note that the value portion of the cookie will automatically be urlencoded when you send the cookie, and when it is received, it is automatically decoded and assigned to a variable by the same name as the cookie name.
This function accepts different number of arguments or parameters. You can see the php reference manual of setcookie function here for more details.
In the following example we are passing 3 parameters
1) cookie name - its the name by which cookie will be identified.
2) cookie value - its the value stored in cookie.
3) expiration time - the time till the cookie will be available, after that it will be destroyed.
You can set the cookie by using above function.
more details can be found here for more details.
To set a cookie use the function "setcookie"
Note that the value portion of the cookie will automatically be urlencoded when you send the cookie, and when it is received, it is automatically decoded and assigned to a variable by the same name as the cookie name.
This function accepts different number of arguments or parameters. You can see the php reference manual of setcookie function here for more details.
In the following example we are passing 3 parameters
1) cookie name - its the name by which cookie will be identified.
2) cookie value - its the value stored in cookie.
3) expiration time - the time till the cookie will be available, after that it will be destroyed.
You can set the cookie by using above function.
more details can be found here for more details.
Selasa, 15 Desember 2009
List files of a Directory in php or List files of a folder from php code
Hi,
In the below code there is one array $exclude, in this array you specify the files which you want to ignore in your final output, so it will not be shown. And just modify the if loop.
If you know any other way to do the same then comments are always welcome.
Dont forget to tell your friends about http://programming-in-php.blogspot.com
You might require this code which lists all files from a specific directory in php. It shows the files from a folder you want.
Even you can specify which files to ignore eg. when showing image you dont want to show thumbs.db file, so you can specify in the code neglect thumbs.db file.
So your code will show all files except thumbs.db
This is a very basic program, you can extend it to a level you want as per your requirement. If you need some help ask me, if possible definitely i will help.
In the below code there is one array $exclude, in this array you specify the files which you want to ignore in your final output, so it will not be shown. And just modify the if loop.
If you know any other way to do the same then comments are always welcome.
Dont forget to tell your friends about http://programming-in-php.blogspot.com
Minggu, 13 Desember 2009
New version 3.0.2 of PHP MicroCMS Pro released
PHP MicroCMS allows users with very little technical knowledge to build websites, as done by millions of bloggers on the web. PHP MicroCMS requires NO knowledge of HTML, although HTML can be used to enhance the pages by adding headings, images, hyperlinks or simply to emphasize text. The new version 3.0.2 of PHP MicroCMS Pro is available for downloading. There are many changes and additions in
Sabtu, 05 Desember 2009
New version 6.0.5 of PHP DataGrid
The new version 6.0.5 of PHP DataGrid is available now for downloading. There are many bugs fixed and also some important improvements, like using [CANCEL] and [UPDATE] in customized layout, drawing floating tooltips with single quotation mark etc. This version requires full re-installation, if you work with one of previous. Read carefully Getting Started. Here the main additions and
Minggu, 29 November 2009
Dropdown - On change redirect to another page
Hi,
Now whenever a user selects any option from the dropdown at that time we are calling our javascript function gotourl which will process the current request and redirects users to that particular page.
Here is our Javascript function gotourl to do processing
Here is full code
If you know any other way to do the same then comments are always welcome.
Dont forget to tell your friends about http://programming-in-php.blogspot.com
Do you want your visitors to go to a particular page when they select any option from the dropdown list or from select box ?
Then here is the select element which will redirect users to the particular url when the select any option from it.
Now whenever a user selects any option from the dropdown at that time we are calling our javascript function gotourl which will process the current request and redirects users to that particular page.
Here is our Javascript function gotourl to do processing
Here is full code
If you know any other way to do the same then comments are always welcome.
Dont forget to tell your friends about http://programming-in-php.blogspot.com
Sabtu, 28 November 2009
New version 3.0.2 of ApPHP Calendar is available now.
The new version 3.0.2 of ApPHP Calendar is available now for downloading. There are many bugs fixed and also some new additions and improvements, like events managing, multi-lingual support, possibility to add event from Weekly View etc. This version requires full re-installation, if you work with one of previous.
Here the main additions and improvements:
* Feature: [added] possibility to
Jumat, 20 November 2009
New version 3.0.1 of ApPHP Calendar
The new version 3.0.1 of ApPHP Calendar is available now for downloading. There are many bugs fixed and also some new additions and improvements, like improved functionality and new features. This version requires full re-installation, if you work with one of previous.
Here the main additions and improvements:
* Feature: [added] possibility to drag Add Event form
* Feature: [added]
Kamis, 19 November 2009
Get number of days between two dates using MySQL?
How can we know the number of days between two given dates using MySQL ? or find the difference between dates using MySQL ?
Do you ever faced this question in technical interview or technical test?
I know many of you have faced this....... :)
Here is a simple function which can be used to find the number of days between two given dates in MySQL.
Syntax - DATEDIFF(firstdate,seconddate)
so internally it will calculate the difference in MySQL by doing "firstdate minus seconddate", so if firstdate is greater than sencoddate then output will be positive and if firstdate is less than seconddate then output will be negative.
eg. if you use this function as
SELECT DATEDIFF('2009-11-19', '2009-10-15');
in MySQL
then you will get output as 35.
And if you pass parameters as
SELECT DATEDIFF('2009-10-15','2009-11-19')
then you will get output as -35.
If you know any other way to find the difference between dates then comments are always welcome.
Dont forget to tell your friends about http://programming-in-php.blogspot.com
Do you ever faced this question in technical interview or technical test?
I know many of you have faced this....... :)
Here is a simple function which can be used to find the number of days between two given dates in MySQL.
Syntax - DATEDIFF(firstdate,seconddate)
so internally it will calculate the difference in MySQL by doing "firstdate minus seconddate", so if firstdate is greater than sencoddate then output will be positive and if firstdate is less than seconddate then output will be negative.
eg. if you use this function as
SELECT DATEDIFF('2009-11-19', '2009-10-15');
in MySQL
then you will get output as 35.
And if you pass parameters as
SELECT DATEDIFF('2009-10-15','2009-11-19')
then you will get output as -35.
If you know any other way to find the difference between dates then comments are always welcome.
Dont forget to tell your friends about http://programming-in-php.blogspot.com
Selasa, 17 November 2009
Difference between sort & asort in php ?
Many times when you go for an interview or technical test you may find this question
sorttype is Optional. Specifies how to sort the array values.
* SORT_REGULAR - Default. Treat values as they are (dont change types)
* SORT_NUMERIC - Treat values numerically
* SORT_STRING - Treat values as strings
* SORT_LOCALE_STRING - Treat values as strings, based on local settings
This function assigns new keys for the elements in the array. Existing keys will be deleted.
so the output of the above code will be -
initial array contents -
Array ( [a] => chaprak [b] => programming [c] => dexter )
and after applying sort function -
Array ( [0] => chaprak [1] => dexter [2] => programming )
its keys are changed to numeric values and sorting is done.
View php manual for the array sort function
* asort() function syntax - asort(array,sorttype)
The asort() function sorts an array by the values. The values keep their original keys (index).
sorttype is Optional. Specifies how to sort the array values.
* SORT_REGULAR - Default. Treat values as they are (don't change types)
* SORT_NUMERIC - Treat values numerically
* SORT_STRING - Treat values as strings
* SORT_LOCALE_STRING - Treat values as strings, based on local settings
when we execute above code then it will produce the following output
initially array contents are - Array ( [a] => chaprak [b] => programming [c] => dexter )
after applying asort() function the contents are -
Array ( [a] => chaprak [c] => dexter [b] => programming )
"What is the difference between the sort() and asort() function in php ?"
Basically sort() and asort() functions are used to sort the array in php.
* sort() function syntax - sort(array,sorttype)
sorttype is Optional. Specifies how to sort the array values.
* SORT_REGULAR - Default. Treat values as they are (dont change types)
* SORT_NUMERIC - Treat values numerically
* SORT_STRING - Treat values as strings
* SORT_LOCALE_STRING - Treat values as strings, based on local settings
This function assigns new keys for the elements in the array. Existing keys will be deleted.
eg. See the code below when we create array $myarray we have assigned keys as a b & c.
Now we are applying sort function and printing the array.
Now we are applying sort function and printing the array.
so the output of the above code will be -
initial array contents -
Array ( [a] => chaprak [b] => programming [c] => dexter )
and after applying sort function -
Array ( [0] => chaprak [1] => dexter [2] => programming )
its keys are changed to numeric values and sorting is done.
View php manual for the array sort function
* asort() function syntax - asort(array,sorttype)
The asort() function sorts an array by the values. The values keep their original keys (index).
sorttype is Optional. Specifies how to sort the array values.
* SORT_REGULAR - Default. Treat values as they are (don't change types)
* SORT_NUMERIC - Treat values numerically
* SORT_STRING - Treat values as strings
* SORT_LOCALE_STRING - Treat values as strings, based on local settings
when we execute above code then it will produce the following output
initially array contents are - Array ( [a] => chaprak [b] => programming [c] => dexter )
after applying asort() function the contents are -
Array ( [a] => chaprak [c] => dexter [b] => programming )
Kamis, 05 November 2009
check whether the url exists or not in php
Whenever it is required to get some input url from user then the first things comes is check whether that url is working and valid or it is not working.
Here is a simple function which can be used to verify the liveness of the url.
Just pass the url to this function and it will tell you whether the url is working and valid or invalid.
In the function "check_url" we are going to open the given url with "fopen".
If its opened then return true else return false.
Now we are going to use this function.
you can pass the url from the GET or POST method to the function.
Here we are going to specify it directly in the code.
So we are asking our code to open the url http://www.chaprak.com with our function.
so after execution it will show the message as
http://www.chaprak.com is a valid URL.
See its very simple to check the validity of the url in php.
Full source code to try is here -
If you have any ideas and suggestions to improve this function then comments are always welcome.
Dont forget to tell your friends about http://programming-in-php.blogspot.com
Here is a simple function which can be used to verify the liveness of the url.
Just pass the url to this function and it will tell you whether the url is working and valid or invalid.
In the function "check_url" we are going to open the given url with "fopen".
If its opened then return true else return false.
Now we are going to use this function.
you can pass the url from the GET or POST method to the function.
Here we are going to specify it directly in the code.
So we are asking our code to open the url http://www.chaprak.com with our function.
so after execution it will show the message as
http://www.chaprak.com is a valid URL.
See its very simple to check the validity of the url in php.
Full source code to try is here -
If you have any ideas and suggestions to improve this function then comments are always welcome.
Dont forget to tell your friends about http://programming-in-php.blogspot.com
Selasa, 03 November 2009
function to count number of words in string in php
Here is a simple function which can be used to count the total number of words present in a string in php.
For this function we are going to use inbuilt functions in php like count, explode, trim.
Function is very simple, it accepts the text.
Then we are checking if there are any extra spaces before and after the string, if it is there then removing that with trim function.
Then we are using count and explode function.
Explode will divide the text into array. (for more information on how explode works visit our post Split string with php explode function and print array)
Then we are counting the total number of array elements by using count function.
Now we are actually going to use this function.
Here is a full source code to try it out.
If you have any ideas and suggestions to improve this function then comments are always welcome.
For this function we are going to use inbuilt functions in php like count, explode, trim.
Function is very simple, it accepts the text.
Then we are checking if there are any extra spaces before and after the string, if it is there then removing that with trim function.
Then we are using count and explode function.
Explode will divide the text into array. (for more information on how explode works visit our post Split string with php explode function and print array)
Then we are counting the total number of array elements by using count function.
Now we are actually going to use this function.
Here is a full source code to try it out.
If you have any ideas and suggestions to improve this function then comments are always welcome.
Kamis, 29 Oktober 2009
function to show read more link in php
Have you ever came across a situation where you need to truncate the large text and show the "read more.." link to redirect user to read the full post ?
I know you might be searching for a function to show read more link in php.
Here is our simple function which can be used to show the "Read more.." links dynamically.
The above function can be used anywhere to show read more links with dynamic mysql queries.
How to use this function ???
Here is a simple example to do this
First you will need to create the connection with the database.
Connection settings are stored in "connect.php" file
This will output your article text with proper linking to original post with read more link.
Even you can customize the truncate function for more security check and customizing your display.
Share with friends if you liked it.
I know you might be searching for a function to show read more link in php.
Here is our simple function which can be used to show the "Read more.." links dynamically.
The above function can be used anywhere to show read more links with dynamic mysql queries.
How to use this function ???
Here is a simple example to do this
First you will need to create the connection with the database.
Connection settings are stored in "connect.php" file
This will output your article text with proper linking to original post with read more link.
Even you can customize the truncate function for more security check and customizing your display.
Share with friends if you liked it.
Minggu, 25 Oktober 2009
How to create and execute, run php file on windows
So you installed WampServer on Windows.
Save the file to the directory mytest as index.php
Now click on the icon present in the right hand side of your taskbar and then click on localhost
Now you will see the list of projects, then click on mytest, you can see that your program is executed.
It will show you all the details of the php version you have installed.
Now how to create and execute or run you php file on windows ???
First START WampServer by clicking your START MENU and then selecting WampServer and then click start WampServer.
Once Server is started then you will see a WampServer icon in the right corner of your taskbar where your clock is present.
Now open the drive where you installed your wampserver.(ex. C:/wamp/)
Then open the www folder. (ex. C:/wamp/www/)
This is your Base directory, your all projects will come here.
Now create a directory here named mytest.
Now open notepad or any other text editor you have. Type the following in it.
Save the file to the directory mytest as index.php
Now click on the icon present in the right hand side of your taskbar and then click on localhost
Now you will see the list of projects, then click on mytest, you can see that your program is executed.
It will show you all the details of the php version you have installed.
Sabtu, 24 Oktober 2009
How to use PHP on Windows - WampServer
Many of us use windows operating system and want to know how to use php on Windows operating system ?
For this there is a very simple and useful solution. Even you don't have to setup & configure many things.
Following things are required for using php on windows
For this there is a very simple and useful solution. Even you don't have to setup & configure many things.
Following things are required for using php on windows
- Apache Server
- Mysql
- PHP
WampServer is a Windows web development environment. With this we can create web applications with Apache, PHP and the MySQL database. Even PHPMyAdmin is provided to manage your databases.
Just Download WampServer and install it and you are done. WampServer is an open source project, free to use.
Once Installation is complete then click here to know how to create and execute(run) a php file on windows.
Jumat, 23 Oktober 2009
Share your blog links, blogs, websites
Hi Friends, programming-in-php.blogspot.com is a place to share experience and knowledge.
You can Help us to spread the word either by forwarding this URL or putting this on your blog or website.
Even I am thinking of putting a section which will list the useful resources for programming, so if you have a blog or website which is related to php, php codes, php scripts, ajax, css, html,open source or if its technical blog then please contact me by writing a comment here about your blog, i will definitely like to add your link here on my blog.
Because to share our knowledge it has to be accessible to other many people. So lets help each other to share knowledge.
We all can have a section on our blog or website to share some useful resources which also helps in link building & SEO(Search Engine Optimization) and promotion.
Your comments are always welcome about this idea, whether is good or bad.
I am waiting for your reply.
Thank you.
Jumat, 16 Oktober 2009
New version 6.0.4 of PHP DataGrid
The new version 6.0.4 of PHP DataGrid is available now for downloading. There are many bugs fixed and also some new additions and improvements, like improved scrolling and multi-row editing. This version requires full re-installation, if you work with one of previous. Read carefully Getting Started. Here the main additions and improvements:* Feature: [added] non-documented attribute for fields
Jumat, 09 Oktober 2009
New version 3.0.3 PHP AdminPanel Pro
The new version 3.0.3 of PHP AdminPanel Pro is available now for downloading. There are many bugs fixed and also Many NEW additions and improvements. This version requires full re-installation, if you work with one of previous. All recent changes can be viewed here.
Check here our Tour and Screenshots!
And new DataGrid Pages Wizard Online DEMO
The Features:
• One-Year FREE Updates
•
Rabu, 07 Oktober 2009
Send Feedback or contact via mail function in php
At many places we require the contact us or feedback form to get some input from the user or to get some feedback from the user.
Today i will be showing you how to create a very simple feedback form or contact us form in php with the mail function and without any database.
1) First we will be creating a simple form to accept the user input like name, email and their message or feedback or query.
2) In the form tag we have not specified any action part and we kept action="" in the form tag, so when the form is submitted at that time it will call itself.
So on submit we will execute our code to send the mail.
Today i will be showing you how to create a very simple feedback form or contact us form in php with the mail function and without any database.
1) First we will be creating a simple form to accept the user input like name, email and their message or feedback or query.
2) In the form tag we have not specified any action part and we kept action="" in the form tag, so when the form is submitted at that time it will call itself.
So on submit we will execute our code to send the mail.
Selasa, 06 Oktober 2009
get current working directory in php - simple function
sometimes it is required to get the current working directory of the script.
so to get the current working directory in php this is a small function.
so to get the current working directory in php this is a small function.
Senin, 28 September 2009
New version 2.0.4 of PHP Easy Installer
The new version 2.0.4 of PHP Easy Installer is available for downloading from here. There are some changes in this version. Read carefully Getting Started. There are some important changes and additions in this version: • Feature: [added] short_open_tag checking while installation• Feature: [added] checking for writability of config file directory • Bugs fixedTo view a Live Demo click here.To
Minggu, 27 September 2009
New version 2.0.1 of PHP DataForm
The new version 2.0.1 of PHP DataForm is available now for downloading. There are many bugs fixed and also some new additions and improvements. This version requires full re-installation, if you work with one of previous. PHP Dataform (PHP DF) script is a simple tool for creating HTML Forms with ease. It was especially designed for web developers, who do not want to spend excessive time on
Rabu, 23 September 2009
Show random quotes on page every time a page is refreshed
This code can be used to show some random quotes or random links every time the page is loaded or refreshed.
$quote = array(
1 => "Random Quote 1",
2 => "This is sample quote 2",
3 => "check http://programming-in-php.blogspot.com",
4 => "it really works",
5 => "wooooooooooooooooooooow",
6 => "I am on twitter"
);
$randnum = rand(1,6);
echo "Random Quote - $quote[$randnum]";
?>
Minggu, 13 September 2009
Split string with php explode function and print array
If it is needed to Split string in php and then use those splitted values for some processing in that case you can use this script which Splits string with php explode function and prints array.
$string = "Contents of the string can be splitted by explode function.";
$splitted = explode(" ",$string);
$cnt = count($splitted);
$i=0;
while($cnt > $i)
{
echo "$splitted[$i]";
echo "\n";
$i++;
}
?>
Sabtu, 12 September 2009
Caution while using JavaScript
Caution: While using Javascript and an alert message is fired using a timer, then keep the timer for atleast 10 seconds, i.e. 10000. Else, the system will hang. I experienced it recently.
Please note.
Please note.
Jumat, 11 September 2009
New version 3.0.1 PHP AdminPanel Pro
The new version 3.0.1 of PHP AdminPanel Pro is available now for downloading. There are many bugs fixed and also some new additions and improvements. This version requires full re-installation, if you work with one of previous. All recent changes can be viewed here.For as little as few minutes you get professional looking and fully functional Admin Panel for your new or existing site. It
Kamis, 10 September 2009
This is for Horizontal Menu.
This part is for Horizontal Menu using CSS.
The below one will come under the Head Tag.
The below one will come under Body Tag.
This code was taken from http://www.w3schools.com/css/tryit.asp?filename=trycss_float5
The below one will come under the Head Tag.
The below one will come under Body Tag.
This code was taken from http://www.w3schools.com/css/tryit.asp?filename=trycss_float5
Rabu, 09 September 2009
Show random quotes on page refresh with php
This is very simple and useful php script if you want to display some random quotes each time a page is visited or refreshed.
This is a very basic version of the script.
Soon you can see the modified version of this script with database support to show random quotes from the database.
$quote = array(
1 => "Random Quote 1",
2 => "This is sample quote 2",
3 => "check http://programming-in-php.blogspot.com",
4 => "it really works",
5 => "wooooooooooooooooooooow",
6 => "I am on twitter"
);
$randnum = rand(1,6);
echo "Random Quote - $quote[$randnum]";
?>
This is a very basic version of the script.
Soon you can see the modified version of this script with database support to show random quotes from the database.
Selasa, 08 September 2009
New product - PHP MicroCMS Pro 3.0.1
PHP MicroCMS allows users with very little technical knowledge to build websites, as done by millions of bloggers on the web. PHP MicroCMS requires NO knowledge of HTML, although HTML can be used to enhance the pages by adding headings, images, hyperlinks or simply to emphasize text. The new version 3.0.1 of PHP MicroCMS Pro is available for downloading. There are many changes and additions in
Senin, 07 September 2009
Display text file contents on webpage in php
Sometimes it is required to show the contents of some text file to the web page. So we can change those contents easily without any problem.
First we will create a simple text file, with some contents.
name it as "test.txt"
Now we will create our php file which will show the contents of the test.txt file to the webpage.
Now when we execute this script, it will show the contents of the test.txt to our page.
In this script we are checking whether file exists or not, it it doesnt exists then we will show the error message.
First we will create a simple text file, with some contents.
name it as "test.txt"
These contents are saved in test.txt file.
I am showing you the contents of some text file.
Its very useful to show the contents of the text file in a browser.
Now we will create our php file which will show the contents of the test.txt file to the webpage.
$file1="test.txt";
if (file_exists($file1))
{
$file = fopen("test.txt", "r");
while (!feof($file))
{
$display = fgets($file, filesize("test.txt"));
echo $display . "
";
}
fclose($file);
}
else
{
echo "Error occured ! ! ! Try again or report it to us";
}
?>
?>
Now when we execute this script, it will show the contents of the test.txt to our page.
In this script we are checking whether file exists or not, it it doesnt exists then we will show the error message.
Factorial of a number in php
This is a small program which generates a factorial of a number in php.
Its a very basic program which generates a factorial of small numbers.
function doFactorial ($x) {
if ($x <= 1)
return 1;
else
return ($x * doFactorial ($x-1));
}
while($i<100)
{
print $i." --> ".(doFactorial ($i)) . "
";
$i++;
}
?>
Its a very basic program which generates a factorial of small numbers.
Minggu, 06 September 2009
Restrict the text in textarea - limit the length of textarea with javascript
sometimes it is required to restrict the length of the textarea so that user should not enter characters beyond a certain limit.
For this we can make use of this simple javascript.
First we will create a 2 textarea.
Here we have created 2 textboxes "mytextarea" and "mytextarea1".
and onkeyup event of the mytextarea we will call our javascript function "restrict(textareaname)", means whenever any key is pressed we will call our javascript function.
and onchange event of the mytextarea we will call our javascript function "restrict(textareaname)", means whenever we will move out of this textbox javascript function will be called.
Here is our javascript function
Include this function either in the head section or at the end before body tag.
Here is full source code to try this
For this we can make use of this simple javascript.
First we will create a 2 textarea.
Here we have created 2 textboxes "mytextarea" and "mytextarea1".
and onkeyup event of the mytextarea we will call our javascript function "restrict(textareaname)", means whenever any key is pressed we will call our javascript function.
and onchange event of the mytextarea we will call our javascript function "restrict(textareaname)", means whenever we will move out of this textbox javascript function will be called.
Here is our javascript function
function restrict(mytextarea) {
var maxlength = 15; // specify the maximum length
if (mytextarea.value.length > maxlength)
mytextarea.value = mytextarea.value.substring(0,maxlength);
} // -->
Include this function either in the head section or at the end before body tag.
Here is full source code to try this
Jumat, 04 September 2009
Generate a random password in php
Today we will be seeing a small easy function to generate a password of specified length.
For this we will be creating a function called "genpwd()"
Now this function is ready, now we want to display the generated password of our specified length.
For this we will print the function value, specifying the length of the password to be generated.
The full working sample example is here, you can copy and paste this code to try it out. It will generate a random string everytime you refresh the page.
UPDATE : 12th September 2009 Hey thanks Filip. Here is one more function to generate a random password suggested by Filip in comments below.
UPDATE : 17th December 2009. Hey thanks Fredrik Karlström. Here is one more function to generate a random password suggested by Fredrik Karlström in comments below
For this we will be creating a function called "genpwd()"
Now this function is ready, now we want to display the generated password of our specified length.
For this we will print the function value, specifying the length of the password to be generated.
The full working sample example is here, you can copy and paste this code to try it out. It will generate a random string everytime you refresh the page.
function genpwd($cnt)
{
// characters to be included for randomization, here you can add or delete the characters
$pwd = str_shuffle('abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890@#%$*');
// here specify the 2nd parameter as start position, it can be anything, default 0
return substr($pwd,0,$cnt);
}
echo genpwd(10); // specify the length of the generated password
UPDATE : 12th September 2009 Hey thanks Filip. Here is one more function to generate a random password suggested by Filip in comments below.
function passwordGenerator($length = null)
{
$pass = md5(time());
if($length != null) {
$pass = substr($pass, 0, $length);
}
return $pass;
}
echo passwordGenerator(6);
UPDATE : 17th December 2009. Hey thanks Fredrik Karlström. Here is one more function to generate a random password suggested by Fredrik Karlström in comments below
function generate_password($len = 8) {
$chars = str_split('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#');
$pwd = '';
for($i=0; $i < $len; $i++)
$pwd .= $chars[rand(1, $sizeof($chars)) -1];
return $pwd;
}
onclick select the text of a textarea
Sometimes we require that when the users click on a textarea at that time all the text should get selected.
This can be done with a small javascript.
When a user clicks on a textarea then all the contents will get selected.
This can be done with a small javascript.
When a user clicks on a textarea then all the contents will get selected.
Kamis, 03 September 2009
Center all contents of website - cetering a website
Hi guys,
We will create a div with id "outer-div" in the body tag of our webpage.
Now we will apply a CSS styling to the "outer-div" div.
The full code to test is here
Generally we require that all the contents of our website should be centered to display the website properly.
For this we can make use of this code so that your website will be in the center of the browser, doesnt matter what is the resolution.
We will create a div with id "outer-div" in the body tag of our webpage.
Now we will apply a CSS styling to the "outer-div" div.
The full code to test is here
Selasa, 01 September 2009
Javascript to show how many characters are remaining to enter in textbox or textarea
Hello,
Today we will be seeing a javascript which will help us to show how many characters are remaining for a textbox or textarea,As soon as the user starts typing in a textbox or textarea, then we will show how many characters are remaining for entering into the textbox.
Here we are creating a simple textbox, and we are specifying the "maxlength" of the textbox to 20.
And "onKeyUp" event of the textbox we are calling a javascript function "countCharacters()".
we will be writing a standard function which accepts only some parameters and rest of the processing will be done in the function.
To this function we have to pass 3 parameters
1) id of the span - where counter will be shown when user types something
2) max_chars - length of the textarea which we specified in maxlength="20"
3) myelement - the id of the textbox where user types text
The function is as below
Now you can use this function anywhere, without a need to modify this function.
The full code to try out is here
Put a link back to our site, if you like this !
Today we will be seeing a javascript which will help us to show how many characters are remaining for a textbox or textarea,As soon as the user starts typing in a textbox or textarea, then we will show how many characters are remaining for entering into the textbox.
Here we are creating a simple textbox, and we are specifying the "maxlength" of the textbox to 20.
And "onKeyUp" event of the textbox we are calling a javascript function "countCharacters()".
we will be writing a standard function which accepts only some parameters and rest of the processing will be done in the function.
To this function we have to pass 3 parameters
1) id of the span - where counter will be shown when user types something
2) max_chars - length of the textarea which we specified in maxlength="20"
3) myelement - the id of the textbox where user types text
The function is as below
Now you can use this function anywhere, without a need to modify this function.
The full code to try out is here
Put a link back to our site, if you like this !
Senin, 31 Agustus 2009
PHP for converting numbers into words (upto one lakh)
Here is a way to convert numbers to words (upto one lakh). It can be extended as per your requirement as well. This is useful for billing etc. Note that only one parameter should be input, and not both. The second parameter is used only for some internal recursive calling.
Minggu, 30 Agustus 2009
Simple css 1 level Vertical navigation menu
Hi,
Now we will apply our css to this ul
Full code of the vertical menu with css is as, just copy and paste it, and modify links and its over.
Today i will be showing you how to create a simple 1 level vertical navigation menu with the help of css.
It is very easy and same like the 1 level horizontal navigation menu.
So lets start,
first we will create a simple code to display "unordered list" with ul and li
Now we will apply our css to this ul
Full code of the vertical menu with css is as, just copy and paste it, and modify links and its over.
Sabtu, 29 Agustus 2009
New version 6.0.2 of PHP DataGrid
The new version 6.0.2 of PHP DataGrid is available for downloading from here. The new version 6.0.2 of PHP DataGrid is available now for downloading. There are many bugs fixed and also some new additions and improvements. This version requires full re-installation, if you work with one of previous. Read carefully Getting Started. Here the main additions and improvements:• Feature: [added] added
Jumat, 28 Agustus 2009
Simple css 1 level horizontal menu
Hi friends,
Now this will create an unordered list.
Now we will apply a CSS to this unordered list to make it a horizontal navigation menu.
Hey ! Its ready ! See it !
Completed ready use script and code is here
here is a simple example of 1 level horizontal navigation menu.
for this i am using 2 images - one is orange and another is blue
you can copy these images from here
1) Orange image
2) Blue image
For creating a "1 level horizontal navigation menu" we are going to use "unordered list"
Now this will create an unordered list.
Now we will apply a CSS to this unordered list to make it a horizontal navigation menu.
Hey ! Its ready ! See it !
Completed ready use script and code is here
Kamis, 27 Agustus 2009
Create a login box with css, html
We always require some kind of login box for any system which has members.
Replace "youfilename.php" with your script which has the logic to check the login.
When you will add this code to your login file then display will be like this - fully stretched on the page with a simple look.
Here i will be showing a simple example with the help of CSS and HTML to create a attractive login box.
To begin with We will create a login box first and then apply the CSS to it
Replace "youfilename.php" with your script which has the logic to check the login.
When you will add this code to your login file then display will be like this - fully stretched on the page with a simple look.
Now we will add a css to this login box to make it look nice.
Now combining all together we have created a very simple nice looking login box without using any other images.
Full source code is given below. Just copy and paste it in your project, if necessary just modify the css.
free php scripts and free php codes
Hi,
Here you will find lots of useful and ready to use free php scripts and codes in php, css, ajax, javascript and many more.....
keep visiting this blog.
Here you will find lots of useful and ready to use free php scripts and codes in php, css, ajax, javascript and many more.....
keep visiting this blog.
Rabu, 26 Agustus 2009
Create a database connection file in php mysql
Whenever you are working on a project you might need to create a database connection and select a database.
Now save this file.
Now just include this file on top of your any other php script.
No need to write code each time.
ex. create a new file called "data.php" and include "connect.php" in that file on top as
Have nice time.
Here i am going to show you a simple way to create your connection file "connect.php"
First create a file and save it as "connect.php"
Now save this file.
Now just include this file on top of your any other php script.
No need to write code each time.
ex. create a new file called "data.php" and include "connect.php" in that file on top as
Have nice time.
Senin, 24 Agustus 2009
Fill select tag with php - fill select tag of form with php
While working on a project you might need a dynamic select box to be generated from the values present in the database.
So this example gives you a simple way to populate a select box with the values present in the database.
Consider a example - there is a table "article" in your database "mydb"
So for this first we need to create a connection with the database and we need to select the database.
For this we will create a file called "connect.php"
replace the values with your actual values as per directed in code
After that we will write our main code in a file called "myselect.php"
And its over. Its very simple.
Try it out, if you face any problem then comment here, i will help you.
So this example gives you a simple way to populate a select box with the values present in the database.
Consider a example - there is a table "article" in your database "mydb"
So for this first we need to create a connection with the database and we need to select the database.
For this we will create a file called "connect.php"
replace the values with your actual values as per directed in code
After that we will write our main code in a file called "myselect.php"
And its over. Its very simple.
Try it out, if you face any problem then comment here, i will help you.
Rabu, 19 Agustus 2009
Show A-Z links for Pagination
Show a-z links on a page for pagination
You can replace $PHP_SELF with the filename for which you want to generate this pagination.
Ofcourse this code doesnt shows the logic to display actually pagination, but instead of taking characters from a-z in a array this is the simple way to show a-z characters for processing.
Soon even i will publish the code to do actual pagination.
You can replace $PHP_SELF with the filename for which you want to generate this pagination.
Ofcourse this code doesnt shows the logic to display actually pagination, but instead of taking characters from a-z in a array this is the simple way to show a-z characters for processing.
Soon even i will publish the code to do actual pagination.
Sabtu, 15 Agustus 2009
New version 6.0.1 of PHP DataGrid
The new version 6.0.1 of PHP DataGrid is available for downloading from here. This is a new generation of DataGrid. There are also some changes in this version. Read carefully Getting Started. This version requires full re-installation, if you work with one of previous versions. Here the main additions and improvements:• Feature: [added] new displaying type "label" for foreign keys• Feature: [
Rabu, 05 Agustus 2009
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
[Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in]
Hi,
when you are doing programming in php you might be getting a error like
[Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in]
this in your php script.
Most of the times if there is mistake in spelling then many errors occurs.
Just check out following things if you encounter this kind of Warning in your php program
- First check your query.
- If you are using different connection file for creating connection then check whether it is included in your script or not.
- If query is correct then check your Database Connection.
Jumat, 17 Juli 2009
New version 1.0.6 of JS Auto Form Validator
New 1.0.6 version of JS Auto Form Validator is available for downloading from here.Changes in this version:-----------------------* Feature: [added] added new language - Japanese* Feature: [improved] checking of email in isEmail() functionBug: [fixed] uppercase for text didn't workTo view a Live Demo click here.
New version of PHP Easy Installer 2.0.3
The new version 2.0.3 of PHP Easy Installer is available for downloading from here. There are some changes in this version. Read carefully Getting Started. There are some important changes and additions in this version: • Feature: [added] possibility to pre-check the current version of PHP• Feature: [added] possibility to define demo|debug and production modes for installation process• Feature:
Senin, 06 Juli 2009
List of Firefox Shortcuts
If you are user of the Firefox web browser then this is the useful place for you.
Here i am listing down some of the common shortcuts.
1) Open new Tab ctrl + t
2) Close current Tab ctrl + w
3) Fullscreen ON / OFF F11
4) Refresh F5
5) Increase Font Size ctrl + +
6) Decrease Font Size ctrl + -
7) Normal Font Size ctrl + 0
8) Find ctrl + F
9) Scroll Down space
10) Scroll Up shift + space
Firefox addons for Web Developers - Download it !
A Great addon for the Firefox ! ! !
If you are want to understand how the page is displayed in firefox browser, how it is divided and showed then you can use the firebug addons for better understanding of the code.
Install this addon from the following URL.
https://addons.mozilla.org/en-US/firefox/collection/firebug_addons
After installation it will ask to restart the firefox.
Restart the firefox and you are done.
After that just right click on any part of the page and click "Inspect Element".
You can alter the code there to see the temporary changes caused by modifying the code or css.
Its very useful for web developers.
If you are want to understand how the page is displayed in firefox browser, how it is divided and showed then you can use the firebug addons for better understanding of the code.
Install this addon from the following URL.
https://addons.mozilla.org/en-US/firefox/collection/firebug_addons
Restart the firefox and you are done.
After that just right click on any part of the page and click "Inspect Element".
A window will be opened showing the code of the element.
You can alter the code there to see the temporary changes caused by modifying the code or css.
Its very useful for web developers.
what is php ?
PHP (Hypertext Pre-Processor)
PHP is a scripting language used for producing dynamic webpages.
PHP is a free open-source server-side scripting language.
PHP code can be embedded in HTML.
You can find the more information about php on the following Wiki link.
Minggu, 05 Juli 2009
php for beginners
If you are a beginner to php then there are some useful resources available on the net to start with.
You can go through following sites to get information.
1) http://www.w3schools.com/PHP/ - This is a very useful website explaining many functions with examples.
more links will be here........
Free php scripts and Programs
Hi everyone,
Here you will find a collection of php scripts and programs.
keep visiting blog for more updates.
Here we are trying to build a large and very helpful database of links, codes, scripts and programs related to php and other technologies.
Jumat, 26 Juni 2009
New product - PHP AdminPanel 2.0.1
PHP AdminPanel (PHP AP) provides you access to the control features of your site as creating static or dynamical pages and allows your easily manage database tables with embedded PHP DataGrid. It includes Creating, Reading, Updating and Deleting (CRUD) records in database tables on your existing site. And also allows you manage menu options in AP "on fly". For as little as few minutes you get
Sabtu, 20 Juni 2009
New version 5.0.7 of PHP DataGrid
The new version 5.0.7 of PHP DataGrid is available for downloading from here.There are some changes in this version. Read carefully Getting Started. This version requires full re-installation, if you work with one of previous versions. Here the main additions and improvements:• Feature: [added] new type of css class "empty"• Feature: [added] new type field type: "money" for fields in Add/Edit/
Minggu, 14 Juni 2009
New version of PHP Easy Installer 2.0.2
PHP Easy Installer is an easy-to-setup PHP script for creating a user-friendly installation wizard. The script is suitable for existing and new web applications. If you plan to create an application in PHP and search for a small, customizable and powerful installation module, then PHP Easy Installer is the best solution for you.The PHP Easy Installer script makes the installation process as
Selasa, 26 Mei 2009
New version 2.0.3 of PHP MicroCMS
PHP MicroCMS allows users with very little technical knowledge to build websites, as done by millions of bloggers on the web. PHP MicroCMS requires NO knowledge of HTML, although HTML can be used to enhance the pages by adding headings, images, hyperlinks or simply to emphasize text. There are many changes and additions in this version: • Feature: [added] Possibility delete images from Image
Sabtu, 16 Mei 2009
New version 5.0.6 of PHP DataGrid
The new version 5.0.6 of PHP DataGrid is available for downloading from here.There are some changes in this version. Read carefully Getting Started.The main additions and improvements:• Feature: [added] new parameter $export_all in AllowExporting() method, that allows exporting of all records• Feature: [added] new non-documented property - allowRealEscape• Feature: [added] new attribute in
Sabtu, 02 Mei 2009
New version of PHP DataGrid 5.0.5
The new version 5.0.5 of PHP DataGrid is available for downloading from here.There are some changes in this version. Read carefully Getting Started.The main additions and improvements:• Feature: [added] non-documented attribute "align"=>"" for fields in edit mode• Feature: [added] new CSS template "x-blue"• Feature: [added] possibility to resize uploaded image• Feature: [improved] CSS styles for
Jumat, 27 Maret 2009
New version of PHP DataGrid 5.0.4
The new version 5.0.4 of PHP DataGrid is available for downloading from here.There are some changes in this version. Read carefully Getting Started.The main additions and improvements:Feature: [added] new attribute for password fields: "cryptography_type"=>"aes|md5"Feature: [added] new attribute for image fields: "linkto"=>"", where possible value is "details"Feature: [added] non-documented
Kamis, 26 Maret 2009
New version 2.0.2 of PHP MicroCMS
PHP MicroCMS (PHP MCMS) is a simple, but very powerful Content Management System that everyone can use. It's very easy to install by web developers, webmasters, graphic designers etc. PHP MCMS was developed in OOP and allows users to build websites in minutes.You can read here a brief list of last changes: Version 2.0.2 • Feature: [added] Checks for using PHP5 or higher on installation • Feature:
Rabu, 18 Maret 2009
New product - PHP MicroCMS 2.0.1
PHP MicroCMS (PHP MCMS) is a simple, but very powerful Content Management System that everyone can use. It's very easy to install by web developers, webmasters, graphic designers etc. PHP MCMS was developed in OOP and allows users to build websites in minutes.PHP MicroCMS allows users to build websites with very little technical knowledge, as millions of bloggers do now on the web. It requires NO
Jumat, 06 Maret 2009
New version of PHP DataGrid 5.0.3
The new version 5.0.3 of PHP DataGrid is available for downloading from here.There are some changes in this version. Read carefully Getting Started.Main additions and improvements:• Feature: [added] new attribute for calendar filtering fields: "calendar_type"="popup|floating"• Feature: [added] new language Japanese(ja_utf8) provided by: Yoshiki Osako• Feature: [added] new attribute for barchart
Jumat, 13 Februari 2009
New version of PHP DataFrom 1.0.1
The new version 1.0.1 of PHP DataForm is available for downloading from here.Main features: * Structured and well-formed object oriented Class-skeleton * Usage of common PHP Patterns, like Composition, Factory-methods etc. * Secure through thorough use of checking-classes * Database automated generation of Forms ("built in use of PDO, for DB-independence, and speed") *
Jumat, 09 Januari 2009
New version 5.0.2 of PHP DataGrid
The new version 5.0.2 of PHP DataGrid is available for downloading from here.There are some changes in this version. Read carefully Getting Started.Main additions and improvements:• Feature: [added] new attributes in add/edit/details modes: "aes_cryptography"=>"true", "aes_password"=>""• Feature: [added] new attribute "magnify_power" for image fields.• Feature: [added] possibility to add date
Langganan:
Postingan (Atom)