极
极核实验室

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

AI summary
文章介绍了使用PHP函数处理字符串的方法,包括获取子字符串和正则表达式匹配。通过substr和strripos函数,实现了从特定字符位置提取前后内容,以及从HTML标签中提取文本。展示了如何使用PHP进行字符串操作和数据处理,适用于网页内容提取和文本处理任务。

Repost license

转载需先申请授权,并保留授权码、原文地址和文中 go/affiliate 链接。

Original URL:https://www.geekcorelab.com/post/php-captures-the-content-before-after-and-in-the-middle

<?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
?>

Comments

Discussion

Be kind and keep the discussion friendly.

Your email will not be shown publicly.

Loading...

Markdown supported.

Discussion

0 comments

Internal link graph

Loading internal links…

View linked articles