<?php #Ex: Short Set Ranking Hosting Provider Founded By Year // INPUT $Hosting_Years = array( ‘Bluehost’ => 2003, ‘Dreamhost’ => […]
Formatting A Number With Leading Zeros In PHP
<?php #Ex: Make 4 Digit Integer Or Zerofill An Integer In PHP // INPUT $start_number = 1; $end_number = 100; for($i=$start_number; $i <= $end_number; $i++ […]
Create A Folder If It Doesn’t Already Exist In WordPress Or PHP
<?php if (!file_exists(‘home/public_html/example.com/wp-content/uploads/blog’)) { mkdir(‘home/public_html/example.com/wp-content/uploads/blog’, 0777, true); } ?> According To Question: #mkdir php #check if directory exists php #how to create directory […]
How to Custom Pagination For Custom Post in WordPress?
There are very simple steps for Pagination for any type of Post in WordPress by Shortcode with Ajax. Write this below code in you active WordPress theme’s funcntion.php file. ie: wp-contentthemestwentytwentyfunctions.php Put this shortcode […]
How To Search In PHP Array Element Containing String | Like Binod
$example = array( “who” => “Who is Binod?”, “name” => “Dose Binod Tharu is Binod?”, “where” => […]
How to create and manage log file in php?
Create and manage crud operation log data PHP <?phpfunction crud_log($action = ”,$message = ”,$array_data = array()){ global $handle_crud_log; date_default_timezone_set(“Australia/Sydney”); //Ex. set australia/sydney timezone $crud_log_dir […]
PHP Run Script For Specific IP Address
<?php// Write your IP instead of xxx.xxx.xxx.xxx if(@$_SERVER[‘REMOTE_ADDR’] == ‘xxx.xxx.xxx.xxx’|| @$_SERVER[‘HTTP_X_FORWARDED_FOR’] == ‘xxx.xxx.xxx.xxx’ ){ define( ‘TESTINGMOD’,TRUE);}else{ define( ‘TESTINGMOD’,FALSE);} if(TESTINGMOD){ error_reporting(E_ALL); ini_set(‘display_errors’, 1); // Write test […]
How to prevent SQL injection in PHP?
<?php$con = mysqli_connect(“localhost”,”my_user”,”my_password”,”my_db”);// Check connectionif (mysqli_connect_errno()) { echo “Failed to connect to MySQL: ” . mysqli_connect_error();}if ($_SERVER[“REQUEST_METHOD”] == “POST”) { //unsafe data $unsafe_name = mysqli_real_escape_string($con, […]
How to connect to mysqli database in php?
Create connection.php file and include all CRUD operation’s file for connect database. <?phperror_reporting(0);$DB_HOST = ‘localhost’;$DB_USER = ‘root’; $DB_PASS = ”;$DB_NAME = ‘mysql’;$conn = mysqli_connect($DB_HOST,$DB_USER,$DB_PASS,$DB_NAME);// Check […]
How to define an empty object in PHP?
<?php $ObjAraay = new stdClass(); $ObjAraay->fname = “PHP”; $ObjAraay->lname = “Beginner”; echo “<pre>”; print_r($ObjAraay); echo “</pre>”;?> Result: