需要帮助才能显示以下代码中的最后一个数组:
$string = "localhost/project/vanilla_2/index.php?p=/discussions/MostCommented";
/* Use tab and newline as tokenizing characters as well */
$tok = strtok($string, "/");
while ($tok !== false) {
echo "Word=$tok<br />";
$tok = strtok("/");
截至目前,我得到以下结果:
Word=localhost
Word=project
Word=vanilla_2
Word=index.php?p=
Word=discussions
Word=MostCommented
问题: 如何获得最后的结果? (MostCommented)
由于
答案 0 :(得分:1)
我相信您正在尝试从URL获取最后一个字符串。检查以下行
$string = "localhost/project/vanilla_2/index.php?p=/discussions/MostCommented";
$explode_str = explode("/", $string);
echo end($explode_str);