0

Need help in displaying only the last array from the following code:

 $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("/");

as of now I am getting the following result:

  Word=localhost
  Word=project
  Word=vanilla_2
  Word=index.php?p=
  Word=discussions
  Word=MostCommented

Question: How to get only the last result? (MostCommented)

Thanks

1 Answer 1

1

I believe that you are trying to get last string from URL. Check the following lines

$string = "localhost/project/vanilla_2/index.php?p=/discussions/MostCommented";
$explode_str = explode("/", $string);
echo end($explode_str);
Sign up to request clarification or add additional context in comments.

2 Comments

I think end($explode) should be end($explode_str)
Yes works like a charm, thanks :) you both are a legend!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.