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.

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

Javascript Acceleration

Run this program, and watch the color change accelerate.

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

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.


$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"


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.

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


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.



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.

Kamis, 03 September 2009

Center all contents of website - cetering a website

Hi guys,
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 !