How to use data type string in PHP? It’s the basic question in PHP, mostly newbies have this question in their mind. PHP has some data types like String, Integer, Float, Boolean, Array, Object, NULL, and Resource. The string is one of the most important data
How to Use Data Type String in PHP:
Data type string i. e. you can say, whatever you will type, it will be displayed. You can’t make calculations in this data type. You can type even numbers too in this data type, but these numbers would also be in string format. It means you are not able to make calculations in these numbers.
Data Type String As Text:
If you want to write text in PHP script use the following pattern, first I have declared a variable $name with
<?php $name = "John"; echo $name: ?>
If you rung the above PHP script in any PHP page, the output will be John.
Data Type String As Numeric:
If you want to write numeric numbers in PHP script use the following pattern, first I have declared a variable $age with value of 33, then I have printed it with echo statement. You can do that too.
<?php $age = "33; echo $age; ?>
If you rung the above PHP script in any PHP page, the output will be 33.
Remember that we usually consider numeric numbers as data type integer. but in the above example, we used $age variable as data type string. If you don’t use double quotation around 33, then it will convert in data type integer. But in example, above the value of variable $age is treated as data type string.
Data Type String As Date of Birth:
If you want to write
<?php $date_of_birth = "13-07-1960"; echo $date_of_birth; ?>
If you run the above PHP script in any PHP page, the output will be 13-07-1960.
How to Connect String Variables:
Some time you need to connect string variables each other. This process is called concatenating strings. How to connect string variables each other, if you don’t know how to do this? Just follow these steps.
<?php $name "John"; $profession = "Software Enginee"; $residence = "Finland"; $bio_data = $name . $profession . $residence; echo $bio_data; ?>
You can notice that there is no space among John, Finland and Software Engineer. For applying space among these variables you can reassign values of $bio_data variable as follows:
$bio_data = $name . " " . $profession . " " . $residence;
Now you can check $bio_data variable’s value by printing with echo statement again. as follows:
If you don’t know how to declare variables in PHP, don’t worry about it, I have written a
Dear friends if you want to create polling system in PHP, and you don’t know how to do this, just go to this article, I hope it will help you. 14 Best PHP Scripts for Polling System