- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove the first character of string in PHP?
To remove the first character of a string in PHP, the code is as follows−
Example
<?php $str = "Test"; echo "Before removing the first character = ".$str; $res = substr($str, 1); echo "
After removing the first character = ".$res; ?>
Output
This will produce the following output −
Before removing the first character = Test After removing the first character = est
Example
Let us now see another example
<?php $str = "Demo"; echo "Before removing the first character = ".$str; $res = ltrim($str, 'D'); echo "
After removing the first character = ".$res; ?>
Output
This will produce the following output−
Before removing the first character = Demo After removing the first character = emo
Advertisements