How To Access a Specific Character in a String using PHP?
Submitted by: AdministratorAny character in a string can be accessed by a special string element expression:
► $string{index} - The index is the position of the character counted from left and starting from 0.
Here is a PHP script example:
<?php
$string = 'It's Friday!';
echo "The first character is $string{0} ";
echo "The first character is {$string{0}} ";
?>
This script will print:
The first character is It's Friday!{0}
The first character is I
Submitted by: Administrator
► $string{index} - The index is the position of the character counted from left and starting from 0.
Here is a PHP script example:
<?php
$string = 'It's Friday!';
echo "The first character is $string{0} ";
echo "The first character is {$string{0}} ";
?>
This script will print:
The first character is It's Friday!{0}
The first character is I
Submitted by: Administrator
Read Online PHP Job Interview Questions And Answers
Top PHP Questions
☺ | What is the difference between PHP4 and PHP5? |
☺ | What is the difference between characters \023 and \x23? |
☺ | How To Download and Install PHP on Windows? |
☺ | What are the difference between abstract class and interface? |
☺ | How many ways we can pass the variable through the navigation between the pages? |
Top Coding/Programming Categories
☺ | Python Interview Questions. |
☺ | OOP Interview Questions. |
☺ | Software engineering Interview Questions. |
☺ | PHP Interview Questions. |
☺ | VBA (Visual Basic for Applications) Interview Questions. |