PHP remove all characters before specific string

前端 未结 4 540
傲寒
傲寒 2020-11-30 02:50

I need to remove all characters from any string before the occurrence of this inside the string:

\"www/audio\"

Not sure how I can do this.<

相关标签:
4条回答
  • 2020-11-30 03:12

    I use this functions

    function strright($str, $separator) {
        if (intval($separator)) {
            return substr($str, -$separator);
        } elseif ($separator === 0) {
            return $str;
        } else {
            $strpos = strpos($str, $separator);
    
            if ($strpos === false) {
                return $str;
            } else {
                return substr($str, -$strpos + 1);
            }
        }
    }
    
    function strleft($str, $separator) {
        if (intval($separator)) {
            return substr($str, 0, $separator);
        } elseif ($separator === 0) {
            return $str;
        } else {
            $strpos = strpos($str, $separator);
    
            if ($strpos === false) {
                return $str;
            } else {
                return substr($str, 0, $strpos);
            }
        }
    }
    
    0 讨论(0)
  • 2020-11-30 03:16

    You can use strstr to do this.

    echo strstr($str, 'www/audio');
    
    0 讨论(0)
  • 2020-11-30 03:20

    Considering

    $string="We have www/audio path where the audio files are stored";  //Considering the string like this
    

    Either you can use

    strstr($string, 'www/audio');
    

    Or

    $expStr=explode("www/audio",$string);
    $resultString="www/audio".$expStr[1];
    
    0 讨论(0)
  • 2020-11-30 03:34

    You can use substring and strpos to accomplish this goal.

    You could also use a regular expression to pattern match only what you want. Your mileage may vary on which of these approaches makes more sense.

    0 讨论(0)
提交回复
热议问题