PHP: Return string between two characters

后端 未结 4 1495
余生分开走
余生分开走 2020-12-30 07:09

I am wanting to use \"keywords\" within a large string. These keywords start and end using my_keyword and are user defined. How, within a large string, can I sear

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-30 07:47

    Explode on "*"

    $str = "PHP is the *best*, *its* the *most popular* and *I* love it.";
    $s = explode("*",$str);
    for($i=1;$i<=count($s)-1;$i+=2){
        print $s[$i]."\n";    
    }
    

    output

    $ php test.php
    best
    its
    most popular
    I
    

提交回复
热议问题