String Interview Questions in PHP
- 1) What is String in PHP?
- 2) How to cast a php string to integer?
- 3) How to perform string concatenation in PHP?
- 4) How to get php string length?
- 5) List some escape characters in PHP?
- 6) How to convert special characters to unicode in php?
- 7) How to add double quotes in string in php?
- 8) Explain how php string interpolation is done?
- 9) How to convert string to an array in PHP?
- 10) What is Heredoc in PHP?
- 11) List some PHP library string functions?
- 12) What is use of strtoupper in PHP?
- 13) How to find capital letter in string php?
- 14) Write the syntax of php mb_strtolower function?
- 15) How to convert array to string in php?
- 16) What is difference between stripos and strpos?
- 17) How to reverse a string in PHP?
- 18) What is use of TRIM function in PHP?
- 19) How to add line break in PHP string?
Below are the list of Best PHP String Interview Questions and Answers
The String is a collection or set of characters in sequence in PHP. The String in PHP is used to save and manipulate like an update, delete and read the data.
The int or integer used for a variable into an integer in PHP.
The string concatenation means two strings connect together. The dot ( . ) sign used in PHP to combine two string.
<?php $stringa = " creative "; $stringb = "writing "; echo $stringa . $stringb; ?>
To determine the string length in PHP, strlen() function used.
echo strlen(“creative writing”);
Some list escape characters in PHP there are:-
There is function json_encode() which is converted special characters to Unicode in PHP.
$stringa = " I am good at smiling"; print_r(json_encode($stringa));
The double quotes in string using (" ") sign and write content under this sign. The double quotes convert variable as value.
An example is below:-
$str8 = " need to read data where has to go "; echo $str 8 output: double quotes in the string
echo “ PHP work $str8 output: PHP work need to read data where has to go
The interpolation is adding variables in among a string data. PHP parses the interpolate variables and replaces this variable with own value while processing the string.
The str_split function used to partition of the string into equal length. Then the string part becomes an array element. The array element contains the remaining end string.
$str1 = 'abcdefghijklmnopqrstuvwxyzpq'; $split1 = str_split($str1, 5); print_r($split1);
OUTPUT of the following code
-  = abcde
-  = fghij
-  = klmno
-  = pqrst
-  = uvwxy
-  = zpq
The Heredoc in PHP syntax is a write multi-line string inside PHP without using the single quote and double quotes delimiters. It works using <<< symbol and a token is a mark the end of the string.
The String function used For manipulation the string in PHP.
The strtoupper() function in PHP allows converting the lowercase alphabet into the uppercase alphabet in the string.
To find out the capital letter, the ctype_upper() function is used in PHP. In the string, check the character is in uppercase or not. If a character is uppercase then return True otherwise False.
PHP mb_strtolower function is used to converts uppercase character into lowercase in the string.
$str1 = "I am good "; $str1 = mb_strtolower($str1); echo $str1;
mb_strtolower function does not affect the Unicode characters also.
$str = "Τάχιστη ηξ βαφής ψημένη γη, δρασκελίζει κυνός"; $str = mb_strtolower($str, 'UTF-8'); echo $str;
The array converts into a string in PHP using implode() function. The example shows the below.
$list_arr = array( 'food', 'bread', 'bazar' ); echo implode( ", ", $list_arr );
The stripos and strops are finding the position of the first occurrence of a string in another string.
The strops() function case sensitive or stripos() function is not case sensitive.
You can use PHP inbuilt function strrev() to reverse a string.
<?php $string="priyag"; echo $rev_string= strrev($string); // Output gayirp ?>
The trim() function in the PHP used to remove space and predefined function. This function removes white space and other arguments like a new line, brake line from left to right in the string.
To line break nl2br() function and \n command use in PHP string.
echo nl2br( “ creative writing \n sensitive reading”);
Subscribe Our NewsLetter
Never Miss an Articles from us.
- Common Interview Questions
- Python Flask Interview Questions
- NoSQL interview questions
- JQuery Interview Questions
- C programming interview questions
- AngularJS Interview Questions
- Node JS Interview Questions with Express
- Core Java interview questions
- HTML Interview Questions
- Laravel interview questions
- Wordpress Interview Questions
- PHP Interview Questions