---
title: "php截取特定字符前面后面中间的内容"
url: https://www.geekcorelab.cn/post/php-captures-the-content-before-after-and-in-the-middle
updated: 2026-11-08T07:57:39.869704Z
author: "hhjmk"
summary: "文章介绍了使用PHP函数处理字符串的方法，包括获取子字符串和正则表达式匹配。通过substr和strripos函数，实现了从特定字符位置提取前后内容，以及从HTML标签中提取文本。展示了如何使用PHP进行字符串操作和数据处理，适用于网页内容提取和文本处理任务。"
---

# php截取特定字符前面后面中间的内容

```
<?php
$text = "123456789";
//保存一段文字
echo substr($text,strripos($text,"5")+1);
echo '<br/>';
//输出5之后内容
echo substr($text,0,strrpos($text,"5"));
echo '<br/>';
//输出5之前内容
echo substr(substr($text,0,strrpos($text,"8")),strripos(substr($text,0,strrpos($text,"8")),"5")+1);
//输出5之后8之前的内容
preg_match('/.*?<p>(\d*?)<\/p>.*?/', "<p>www.biliwind.com</p>", $res);
echo $res;
//输出 www.biliwind.com
?>
```
