php

Notes and Practical Projects for learning php while my learning journey

View on GitHub

Server-Side Validation

Removing White-Spaces trim()

$username = trim($_POST['username']);

Special characters addslashes()

$username = addslashes($_POST['username');

Convert String into array

$usernames = explode(':', $colon_separated_names);

String Length

$length = strlen($username);

String To UpperCase

	$strUpper = strtoupper($string);

ucfirst()

	echo ucfirst("hello world!");

ucwords()

	echo ucwords("hello world");

convert \n to <br/>

echo nl2br("List: \n 1- first options \n 2- second options");

Filter variable

// Input Sanitization To Avoid SQL Injection And XSS .....

$username = filter_var($_POST['username'], FILTER_SANITIZE_STRING);

$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);

$password = filter_var($_POST['password'], FILTER_SANITIZE_STRING);

$password = password_hash($password, PASSWORD_DEFAULT);