Question about strpos: how to get 2nd occurrence of a string?

后端 未结 14 1506
广开言路
广开言路 2020-11-27 04:38

I understand that this function will get the first occurrence of the string.

But what I want is the 2nd occurrence.

How to go about doing that?

14条回答
  •  渐次进展
    2020-11-27 05:29

    just worked for me to find if are 2 or more occurrence of a char, then by strlen them i found that exist 2 occurrence ex ( i dont use $matches at all):

    $string = '1234|6|#red';
    
    if(strlen(preg_match_all('/|/', $string,$matches, PREG_OFFSET_CAPTURE)) ==2){
    
    echo 'i have 2 occurence of char: |';
    
        }
    

提交回复
热议问题