phpstringtext-extraction

Get substring after delimiter


I have this string 9|Engineering and I need to get this part Engineering from it, I'm trying to use this piece of code:

substr($program, 0, strrpos($program, '|', 2))

but I'm getting nothing.


Solution

  • try to use str_replace()

    $str = "9|Engineering";
    echo str_replace('9|', '', $str); //Engineering
    

    or

    $str = "9|Engineering";
    echo substr($str,2); //Engineering
    

    or use explode()

    $str = "9|Engineering";
    $re = explode('|', $str); 
    echo $re[1];//Engineering