How to get string between 2 characters in PHP

不言
Release: 2023-04-03 08:54:02
Original
4600 people have browsed it

Today’s article shares with you the method of intercepting a string between two specified characters in PHP. Friends in need can refer to it.

<?php
function getNeedBetween($kw1,$mark1,$mark2){
$kw=$kw1;
$kw=&#39;123′.$kw.&#39;123′;
$st =stripos($kw,$mark1);
$ed =stripos($kw,$mark2);
if(($st==false||$ed==false)||$st>=$ed)
return 0;
$kw=substr($kw,($st+1),($ed-$st-1));
return $kw;
}
?>
Copy after login
$keyword=&#39;查找(计组实验)&#39;
$need=getNeedBetween($keyword, &#39;(&#39; , &#39;)&#39; );
Copy after login

Result:

$need=&#39;计组实验&#39;;
Copy after login

Related recommendations:

php intercept string function sharing, php intercept string

php method to intercept a string between specified 2 characters, intercept the string

The above is the detailed content of How to get string between 2 characters in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template