Cut string after specified character in php

后端 未结 2 641
独厮守ぢ
独厮守ぢ 2021-01-27 06:52

I try to cut a text after the occurence of a specified character, in this case:

The text example is:

...text?“ Text,
         


        
2条回答
  •  盖世英雄少女心
    2021-01-27 07:09

    I think this can be helpful for anyone :

    $title = 'sometext?"othertext';
    $pos2 = strpos($title, '"');
    
    $title = substr($title, 0, $pos2+1);
    
    echo $title;
    

    Output:

    sometext?"


    If you want the text after the " mark:

    $title = 'sometext?"othertext';
    $pos2 = strpos($title, '"');
    
    $title = substr($title, $pos2+1);
    
    echo $title;
    

    Output:

    othertext

提交回复
热议问题