Php 如何读取符号前后的字符/字符串

Php 如何读取符号前后的字符/字符串,php,Php,我想做一个变量,它的资源是一个范围变量,有人能帮我读一下字符串'-'和';'吗 $temp='25-30;18-20'; $tempmin1=//before '-'result is 25 $tempmax1=//after '-' result is 30 $tempmin2=//before '-'result is 18 $tempmax2=//after '-' result is 20 请尝试以下代码: $tem

我想做一个变量,它的资源是一个范围变量,有人能帮我读一下字符串'-'和';'吗

 $temp='25-30;18-20';
        $tempmin1=//before '-'result is 25
        $tempmax1=//after '-' result is 30 
        $tempmin2=//before '-'result is 18
        $tempmax2=//after '-' result is 20 
请尝试以下代码:

$temp='25-30;18-20';
$temparr = preg_split("/\-|\;/", $temp);
现在,

“-”结果为25之前,$temparr[0]将是$tempmin1

“-”结果为30后,$temparr[0]将是$tempmax1

“-”结果为18之前,$temparr[0]将是$tempmin2


“-”后的$temparr[0]将是$tempmax2,结果是20

看看
preg\u split()
最好使用
explode
而不是
preg\u split
你说的话@Rizier123@UchihaOP有多个分隔符,因此
preg\u split