Home > Article > Backend Development > How to Extract a Substring Between Characters Using PHP\'s preg_match()?
Extracting a Substring Between Two Characters in PHP
The PHP preg_match() function can be used to extract a substring between two specific characters within a string. This can be useful for parsing text and extracting specific data.
Let's consider an example:
$input = "[modid=256]"; preg_match('~=(.*?)]~', $input, $output); echo $output[1]; // 256
In this code:
In the example above, the extracted substring would be "256". This technique is particularly useful when you need to extract specific information from text where the substring is surrounded by known characters.
The above is the detailed content of How to Extract a Substring Between Characters Using PHP\'s preg_match()?. For more information, please follow other related articles on the PHP Chinese website!