Skip to content

Instantly share code, notes, and snippets.

View niravmadariya's full-sized avatar
💭
I may be slow to respond.

Nirav Madariya niravmadariya

💭
I may be slow to respond.
View GitHub Profile
@niravmadariya
niravmadariya / GETPOST.php
Last active June 7, 2018 07:01
GET and POST exmaple in PHP
<form action="" method="POST">
<input type="submit" value="submit" name="submit" />
</form>
<form action="">
<input type="submit" value="submit" name="submit"/>
</form>
<?php
if(isset($_POST['submit'])){
echo "Submitted via POST";
@niravmadariya
niravmadariya / FileOperations.php
Last active June 7, 2018 07:02
Basic file operations in PHP
<?php
//reading a file...
$myfile = fopen("webdictionary.txt", "r");
echo fgets($myfile);
fclose($myfile);
//Write to a file...
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "This is new File\n";
fwrite($myfile, $txt);
@niravmadariya
niravmadariya / GreetUser.php
Last active June 7, 2018 07:02
Greet user based on time
<?php
date_default_timezone_set('Asia/Kolkata');
$hour=date('h', time());
$ampm=date('a', time());
if($ampm=="am"){
if($hour>=1 && $hour<=11){
echo "Good Morning!!!";
}
}
@niravmadariya
niravmadariya / FactorialProgram.php
Last active June 7, 2018 07:01
Factorial Program in php
<html>
<head>
<title>Factorial Program using loop in PHP</title>
</head>
<body>
<form method="post">
Enter the Number:<br>
<input type="number" name="number" id="number">
<input type="submit" name="submit" value="Submit" />
</form>
<html>
<head><title>Reverse of a given Number in PHP</title></head>
<body>
<form method="post">
Enter the Number:<br>
<input type="number" name="number" id="number">
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_POST['submit']){
@niravmadariya
niravmadariya / EvenOdd.php
Created June 7, 2018 07:04
Given Number is Even or Odd
<html>
<head><title>Check if the number is Even or Odd</title></head>
<body>
<form method="post">
Enter the Number:<br>
<input type="number" name="number" id="number">
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if($_POST['submit']){
@niravmadariya
niravmadariya / Copyfile.php
Last active June 7, 2018 07:31
Copy file content to another file - PHP
<?php
echo copy("source.txt","target.txt");
//Another way
//Get all the content from the file
$fileContents = file_get_contents('1.txt');
//Output to new file
$fh = fopen('output.txt', 'w+');
file_put_contents($fh, $fileContents);
fclose($fh);
@niravmadariya
niravmadariya / lock.php
Created June 7, 2018 07:35
Lock a file in php
<?php
$file = fopen("test.txt","w+");
// exclusive lock
if (flock($file,LOCK_EX))
{
fwrite($file,"Write something");
// release lock
flock($file,LOCK_UN);
}
else
@niravmadariya
niravmadariya / Arrays.php
Created June 7, 2018 07:49
Numerical and Associative Array Example in php
<?php
$a[0] = 1; // Numeric Array
$a[1] = 2;
$a[2] = 3;
$a[3] = 4;
$a[4] = 5;
$b['a']='a'; // Associative Array
$b['b']='b';
$b['c']='c';
$b['d']='d';
@niravmadariya
niravmadariya / SignupForm.php
Created June 29, 2018 07:11
Signup Form with Captcha
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sign Up Form</title>
</head>
<body>
<section>
<form class="c-form" action="" method="POST">
<div>