There is a string that ends with a single white space. You can use PHP trim function to remove the white space at the end of the string. PHP trim() Function This function not only removes white space at the end of the string but also at the beginning of the string. <?php echo $username; […]
Category: PHP Problem Solver
PHP: Remove Extra Spaces around a string
In many times, you may see there are strings with extra spaces around it and you may want to remove those extra spaces. By using PHP function trim function, you can remove those extra spaces around the string. Example <?php echo $username; ?> Output: ” srikant […]
What are the basic differences between Server Side Scripting(PHP) and Client Side Scripting(Javascript)?
Server side scripting as the name says, the scripts meant for server and client side scripting means the script meant for client. What is sever? To run a website, we must have to keep all the files related to the site at a specific location. This location is called server. Server contains all the files […]
Simple fix for Header already sent error in PHP Scripting
While setting header information we often encounter this error: header already sent and we could not able to figure out exactly what is the error and how to solve it. Headers Already Sent Error First of all we have to understand why this error is rising. Reason When ever we run a php script, along […]
Why do web developers prefer MySQLi over MySQL in PHP Scripting?
Professionals, php Gurus and developers strictly suggest to use mysqli functions in php script. But while developing php application we have witnessed mysql function is working fine in script with latest version of php. Then why we should we go for mysqli functions. MySQL functions in PHP mysql functions in php are the old functions […]
What does notice: Undefined Variable in PHP Scripting mean?
The notice: undefined variable means, as the name it says, the variable is not defined. Notice undefined variable Look at the below code <?php if(!empty($employees_data)){ $employee_phone_number=Get_Employee_Phone_Number(); } echo $employee_phone_number ?> Can you guess, what would be the result? It will show, Notice: undefined variable error. Reason: the variable $employee_phone_number variable is defined inisde the if […]
What is the simplest approach to prevent SQL Injection in PHP Scripting?
Hackers follow sql injection to inject virus, delete data, collect data, change data etc. SQL Injection Hackers keep looking for the loop holes present in a website. Best target points are input fields. Such as login forms which has input fields. With the help of computer program, they find out the vulnerable points. Once they […]
What is the PHP function for obtaining current URL of the web page?
In some cases, we may need to get the current url of the webpage. PHP has super global variables which holds the data related to the webpage url. $_SERVER super global variable PHP has this variable $_SERVER it contains all the web url related info. We need to get two data, one is request uri, […]
What is the efficient way to fix notice undefined offset array index in PHP?
Array datatype in php contains different values and these values are fetched using index number. Often dealing with array, we encounter undefined offset. What causes undefined offset notice? Lets understand with the help of an example. Example <?php $fruits=array(“apple”,”orange”,”grape”, “guava”,”mango”); ?> In the above example, $fruits array contains fruit names. If I want to get […]
Create Table in webpage using PHP Code
The power of PHP is it can easily embed HTML Codes. To create any html elements lets say a table, we can use PHP to create a table. Create Table Using PHP We have to echo out all the table tags and its respective data. Note: If you are looking for a solution to create […]
How to calculate size of an Image using PHP?
One prime approach to implement fast loading webpage is to provide image size that is width and height data to the image tag. It will render fast. Even in Accelerated Mobile Page (AMP) implementation it is mandatory to provide image width and height inside the image tag(amp-img). That’s why we need to calculate the size […]
What is the best way to calculate the size of an Array in PHP?
In some cases we may need to know the number of elements present inside an array. PHP has provided two functions that calculates the total elements present inside an array and returns the value. Count() Function PHP has count function which counts the array size. Example; <? $fruits=array(“orange”,”grape”,”apple”); echo count($fruits); ?> output: 3 sizeOf() function […]
How can we use JSON in PHP Scripting?
JSON in PHP – JSON is not object, not an array or any kind of datastructure. People often misunderstood it. JSON is serialized data. JSON is useful to send data in key value format. JSON – Javascript Object Notation How to use JSON in PHP? Lets understand the usage of json in php files. Example […]
What is the purpose of $_GET in PHP Scripting?
$_GET variable is used in php to collect data that is passed through url. The general case where we use get in a php is during form submission. Form submission sends various data as parameter in the url. At the recipient php file, the data present in the variable is collected. How to use Get […]
How can we use SQL in PHP Server Side Scripting?
PHP has predefined functions that helps us to use SQL syntax inside a php file. SQL in PHP We can execuate following sql related task. Establish connection with database Syntax mysqli_connect(hostname, username, password, databasename) Example <?php $conn=mysqli_connect(“localhost”,”root”,”password”,”root_database”); if($conn){ echo “connected to database”; }else{ echo “failed to connect to the database check connection parameters”; } ?> […]
How can we convert a string value into an Array using PHP?
In php, a string can be converted into an array. PHP has a predefined function explode, which breaks string text into array. String to Array Conversion To convert a string into array lets use php function “Explode” Syntax explode(seperator, string); Note: While converting a string into an Array by using explode php function, keep one […]
PHP: How to convert an Array into a string?
In some cases, we may want to convert an array into a string. There are plenty ways we can achieve the result. Lets learn about most effective ones. Convert An Array To String We can convert an array into a string in following two ways. First one – implement our own logic and second one – to […]