【问题标题】:strrchr only displaying items in string after slashstrrchr 仅在斜杠后显示字符串中的项目
【发布时间】:2013-02-14 00:20:34
【问题描述】:

我正在引用一个数组,这仅显示斜杠后的字符串部分。我如何也显示它之前的字符。

#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, " ");
    }

【问题讨论】:

  • 你能给我们举个例子来说明 $bios[$i] 的值吗?或者,您可以尝试使用 explode() 函数。例如。 $fields = explode(" /", $bios[$i]);
  • $bios = array("President & CEO / Laganatech","销售副总裁 / Elguji Software","会计副总裁 / Drugco Inc.","Programmer / Mobile Solutions, Inc.", “系统分析师/夏普系统”);

标签: php string strchr strrchr


【解决方案1】:

试试这个:

if ($biosDisplayed == $y) {
        $fields = explode(" / ", $bios[$i]);

        echo "<br /><b>Position Title: </b>" . $fields[0];
        echo "<br /><b>Bio: </b>" . $fields[1]);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-23
    • 1970-01-01
    • 1970-01-01
    • 2018-02-27
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多