phpstringstrchrstrrchr

strrchr only displaying items in string after slash


I'm referencing to an array and this is only showing the part of string after the slash. How do I show the characters before it also.

#Check for bio
        if ($biosDisplayed == $y) {
            $positionTitle = strpos($bios[$i], " /");
            $positionTitle = substr($bios[$i], 0, $positionTitle);
            echo "<br /><b>Position Title: </b>" . $positionTitle;

            #Company Name
            $position = strrchr($bios[$i], " /");
            echo "<br /><b>Bio: </b>" . strchr($position, " ");
    }

Solution

  • Try this:

    if ($biosDisplayed == $y) {
            $fields = explode(" / ", $bios[$i]);
    
            echo "<br /><b>Position Title: </b>" . $fields[0];
            echo "<br /><b>Bio: </b>" . $fields[1]);
    }