<?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
?>
php extract content before, after, and between specific characters
Article repost policy
Request authorization before reposting and retain the authorization code, original URL, and go/affiliate links.
- Authorization is required before reposting
- Keep the authorization code, original URL, and go/affiliate links on the reposted page
Original URL: https://www.geekcorelab.cn/en-US/post/php-captures-the-content-before-after-and-in-the-middle