Home >Backend Development >PHP Tutorial >How to get string between 2 characters in PHP

How to get string between 2 characters in PHP

不言
不言Original
2018-07-18 13:45:334660browse

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;
}
?>
$keyword=&#39;查找(计组实验)&#39;
$need=getNeedBetween($keyword, &#39;(&#39; , &#39;)&#39; );

Result:

$need=&#39;计组实验&#39;;

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!

Statement:
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