Top 10 Tips Advanced PHP Developers

Top 10 Tips Advanced PHP Developers

Today, We want to share with you Top 10 Tips Advanced PHP Developers.
In this post we will show you 10 Things You Can Do to Become a Better PHP Developer, hear for The 10 Most Common Example PHP Developers we will give you demo and example for implement.
In this post, we will learn about 10 Advanced PHP Tips with an example.

Read Also:  Advanced jQuery Ajax Pagination PHP MySQL using jQuery

php generate random string of characters

$string = 'DEFCHJJ0123ABC4DSw2waycomP567pakainfo89';
$string_shuffled = str_shuffle($string);
$half = substr($string_shuffled, 1, 4);
echo $half;

PHP urlencode() & urldecode() Functions

$uid=urlencode($uid);
$pin=urlencode($pin);
$sender=urldecode($sender);
$message=urldecode($message);
$tempid=urlencode($tempid);

php convert special characters to html entities

$em=htmlspecialchars_decode($emailid);
$emailaddress=addslashes($em);
$db=htmlspecialchars_decode($dob);
$dobt=addslashes($db);
$bg=htmlspecialchars_decode($bgroup);
$bgp=addslashes($bg);

log genrater file created using PHP

		
function wh_log($msg)
{
	$logfile = 'log/log_' . date('d-M-Y') . '.log';
    file_put_contents($logfile, $msg . "\n", FILE_APPEND);
}	

/*wh_log("########## END[IN FUNCTION getpartylistf($unitid,warehouseid)]'" . date('d-m-Y H:i:s') . "'##########"); */

lastInsertId using PHP script example

$sql="INSERT INTO `usermst` (`userid`, `usermobile`, `regdt`, `status`, `deviceid`, `device_token`) VALUES (NULL, '$mobile', '$dt', '0', '$deviceid', '$dtokenf')";
				 
					wh_log("sqlquery" . $sql);
					$db = getConnection();
					$sqlQQ =  $db->prepare($sql);
					$sqlQQ->execute();
					$new_userid = $db->lastInsertId();

INNER JOIN in mysql with PHP Example

$partySS="select usermst.userid,usermst.usermobile from usermst 
INNER JOIN usergroupmap
ON usermst.userid=usergroupmap.userid
where usergroupmap.groupid=$gid and usermst.userid  $userid ORDER BY userid DESC";

PHP Total No of Records Count using PHP

$deviceT = "SELECT DISTINCT device_token FROM usermst where trim(device_token) != '' and status=5 and userid='$userid'";

$db = getConnection();       
$deviceTStmnt = $db->prepare($deviceT);
$deviceTStmnt->execute();
$deviceTData = $deviceTStmnt->fetchAll(PDO::FETCH_ASSOC);
$deviceTCount = count($deviceTData);

php json_decode to array with php json_encode to array – example

	error_reporting(E_ALL || ~E_NOTICE);
	$user_name = $_POST['name'];
	$user_username = $_POST['username'];
	$user_email = $_POST['email'];
	$user_phone1 = $_POST['phone1'];
	$user_phone2 = $_POST['phone2'];
	$user_password = $_POST['password'];
	
	$req_sub = $_POST['req_sub'];//产品ID
	$rate_post=$_POST['rate'];
	$user_type=$_POST['user_type'];
	$user_bm_percent=$_POST['user_bm_percent'];
	$user_bm_tips=$_POST['user_bm_tips'];
	$user_on_percent=$_POST['user_on_percent'];
	$user_on_tips=$_POST['user_on_tips'];
	$rate=array();
	if(!empty($req_sub)){
		
		foreach($req_sub as $v){
				if(empty($rate_post[$v])){
					$rate[$v]=0;
				}else{
					$rate[$v]=$rate_post[$v];
				}
				
		}
	}
	$req_sub_json=json_encode($req_sub);
	$rate_json=json_encode($rate);
	
	echo "<pre>";
	print_r($req_sub_json);
	print_r($rate_json);
	echo "</pre>";

how to check whether session exists or not in php

	session_start();

	$check = $_SESSION['login_username'];

	if(!isset($check)) {
	    header("Location:index.php");
	}

Demo – Source code

Read Also:  jQuery AJAX file Image upload PHP Example

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  Login with Facebook and Twitter using PHP
  2. Read Also:  AngularJS populate Dynamic Dependent dropdown in PHP
  3. Read Also:  PHP MySQL Connect Database Script
  4. Read Also:  Laravel JSON Encode Decode Handling
  5. Read Also:  Laravel Set cron job in cpanel Scheduling Tutorial
  6. Read Also:  Laravel 6 Eloquent Query Retrieving Single Models
  7. Read Also:  Menu Based Program in PHP Using Switch case
  8. Read Also:  How to Get Last Executed Query in Codeigniter?
  9. Read Also:  Menu Based Program in PHP Using Switch case
  10. Read Also:  PHP MySQL Connect Database Script
CLOSEX