How to usesubstr() Function in PHP
The substr() function is used to extract a substring from a string in PHP. It takes three arguments: the input string, the starting position (zero-based index), and optionally the length of the substring to extract.
<?php
$str = "Welcome to w3wiki";
$subStr = substr($str, 11, 13);
echo $subStr;
?>
Output
w3wiki
How to Extract Substring from a String in PHP?
Given a String, the task is to extract substring from string in PHP. Extracting substrings from a string is a common task in PHP, whether you need to extract a portion of text based on a specific position or find a substring based on a pattern. In this article, we will explore various approaches to extract substrings from a string in PHP.
Table of Content
- Using substr() Function
- Extracting Substring Before a Specific Character
- Using Regular Expressions (Regex)