indexOf and lastIndexOf in PHP?

后端 未结 4 2080
孤独总比滥情好
孤独总比滥情好 2021-02-05 01:38

In Java, we can use indexOf and lastIndexOf. Since those functions don\'t exist in PHP, what would be the PHP equivalent of this Java code?

<         


        
4条回答
  •  囚心锁ツ
    2021-02-05 02:03

    This is the best way to do it, very simple.

    $msg = "Hello this is a string";
    $first_index_of_i = stripos($msg,'i');
    $last_index_of_i = strripos($msg, 'i');
    
    echo "First i : " . $first_index_of_i . PHP_EOL ."Last i : " . $last_index_of_i;
    

提交回复
热议问题