French Money Format with PHP

To format a currency, you can use number_format PHP function. There are also other functions such as money_format(), sprintf(), printf(), sscanf().


$number = 1234567891.23;

// French Money Format
$french_money_format = number_format($number, 2, ',', ' '); 

// The result is 1 234 567 891,23 
echo number_format($number, 2, ',', ' ') . ' ' .'€';
Result

1 234 567 891,23 €

Phone Number Format Using Points

With wordwrap PHP function, you can format a phone number using points between blocks of characters
When an user types his phone number in a form and if you need to shown it, the display is more readable

//Code
$phonenumber = '0123456789';
$phonenumber_formate = wordwrap ($phonenumber, 2, '.', 1); 

//Overview 01.23.45.67.89
echo $phonenumber_formate;

List Files from a Folder with PHP

Opendir Function

(PHP 4, PHP 5, PHP 7) opendir — Open directory handle

Readdir Function

(PHP 4, PHP 5, PHP 7) readdir — Read entry from directory handle

		//Files list
		$nb_files = 0;
		echo '<ul>';
		if ($folder = opendir('./myfolder'))
		{
			while (false !== ($files = readdir(folder)))
			{
				if($files != '.' && $files != '..' && $files != 'index.php')
				{
					$nb_files++; // Incrementation of the repeat counter +1 
					echo '<li  style="list-style-type:none;"><a href="./myfolder/' . $files . '">' . $files . '</a></li>';
				} // The end of 'if' allows do not show index.php
					
			} // End of loop
			
		echo '</ul><br/>';
		echo 'There are <strong>' . $nb_files .'</strong> file(s) in the folder';
			
		closedir($folder);
			
		}
			
		else
			echo 'There are not file in the folder';
	echo '</div>';

First Character Capital with jQuery

Input test



HTML code
<input type='text' id='name' name='name'/>
jQuery code
								<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
								<script>
									$(document).ready(function() {
										$('#prenom').on('keydown', function(e) {
											if (this.value == '') {
											var char = String.fromCharCode(e.which);
												if (char.match(/^\w$/)) {
													this.value = char.toUpperCase();
													return false;
												}
											}
										});
									});
								</script>

Bootstrap Form Code


<!DOCTYPE html>
<html lang="fr">
	<head>
		<meta charset="UTF-8"/>
		<title>Bootstrap</title>
		<!-- Latest compiled and minified CSS -->
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"/>
		<!-- Optional theme -->
		<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous"/>		
		<!-- Latest compiled and minified JavaScript -->
		<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
		<style>
			.class01 {
				padding:2vw;
			}
		</style>
	</head>
	<body>
		<div class="container class01">
			<form class="well col-xs-6 col-sm-6 col-md-4 col-lg-4 center-block">
			  <div class="form-group">
			    <label for="email">Email address</label>
			    <input type="email" class="form-control" id="email"/>
			  </div>
			  <div class="form-group">
			    <label for="pwd">Password</label>
			    <input type="password" class="form-control" id="pwd"/>
			  </div>
			  <div class="checkbox">
			    <label><input type="checkbox"/>Remember me</label>
			  </div>
			  <button type="submit" class="btn btn-large btn-primary">Submit</button>
			</form>
		</div>
	</body>
</html>
Election Worpdress plugin

Election WordPress plugin

Elections Plugin is an essential WordPress plugin and the simply way if you whish to create and run your own election campaign for your company or association.
You can create, manage and run your own election campaign.
Click on this link for more information:
http://www.wp-elections.com/

Display and see PHP errors

Code to display and see PHP errors in your code pages
<?php
// Display the errors on screen
ini_set('display_errors', 1);

// Recorde the errors in a log file
ini_set('log_errors', 1);

// File's name that recordes the logs (be careful to the write permissions)
ini_set('error_log', dirname(__file__) . '/log_error_php.txt');

// Activate the PHP errors report 
error_reporting(E_ALL);
?>

Date Submit Button with jQuery

JS code
$( document ).ready(function() 
{
	var f = new Date();
	var dayNumber = f.getDate();

	var d = new Date();
	var daysWeek = new Array(7);
		daysWeek[0] = "Sunday";
		daysWeek[1] = "Monday";
		daysWeek[2] = "Tuesday";
		daysWeek[3] = "Wednesday";
		daysWeek[4] = "Thursday";
		daysWeek[5] = "Friday";
		daysWeek[6] = "Saturday";				
		
	var e = new Date();
	var months = new Array(12);
		months[0] = "January";
		months[1] = "February";
		months[2] = "March";
		months[3] = "April";
		months[4] = "May";
		months[5] = "June";
		months[6] = "July";
		months[7] = "August";
		months[8] = "Septembre";
		months[9] = "October";
		months[10] = "November";
		months[11] = "December";

	var n = daysWeek[d.getDay()];
	var m = months[d.getMonth()];
	var o = dayNumber;
	
	$('#message').html($("input[type='submit']").attr('value','Submit on' + ' ' + n + ' '  + o + ',' + ' ' + m));
});
HTML code
<html>
  <head>
  </head>
  <body>
    <div id="message">
    </div>
  </body>
</html>






Add, remove CSS class with JavaScript

Change the classes of a HTML element
document.getElementById("myElement").className = "myClass";
Or more classes, separated by a space
document.getElementById("myElement").className = "myClass1 myClass";
To add new classes without removing those already existing
document.getElementById("myElement").className += "myClass3";
Delete the classes of a HTML element
document.getElementById("myElement").className =
document.getElementById("myClass").className.replace( /(?:^|\s)MyClass(?!\S)/g , "" )
Delete the occurrences of myClass in the list of words separated by spaces
if ( document.getElementById("myElement").className.match(/(?:^|\s)myClass(?!\S)/) )

Table with colorization one line in two

$resultat=mysql_query($sql);
$i= 0;
while ($donnees = mysql_fetch_array($resultat) )
{
   $i++;
   if($i%2==0)
  {
  echo '<tr class="ligne1">';
  }
  else
  {
  echo '<tr class="ligne2">';
  }
 
   ?>            
        <td>test</td>
        <td>test</td>
        <td>test</td>
</tr>
.ligne1
{
background-color: white;
}
.ligne2
{
background-color: blue;
}