How do I find the last URL of a segment?

How do I find the last URL of a segment?

You can also use the lastIndexOf() function to locate the last occurrence of the / character in your URL, then the substring() function to return the substring starting from that location: console. log(this. href.

How to get second parameter from URL in javascript?

var url = “http://example.com/param1/param2/param3″; var params = url. replace(/^http:\/\/,”). split(‘/’); // beware of the doubleslash var secondlast = params[params. length-2]; // check for length!!

How do I find the URL of a wordpress segment?

How to Get URI Segment in PHP

  1. $uriSegments = explode(“/”, parse_url($_SERVER[‘REQUEST_URI’], PHP_URL_PATH));
  2. echo $uriSegments[1]; //returns codex. echo $uriSegments[2]; //returns foo. echo $uriSegments[3]; //returns bar.
  3. $lastUriSegment = array_pop($uriSegments); echo $lastUriSegment; //returns bar.

What is the last path of url?

We identify the index of the last / in the path, calling lastIndexOf(‘/’) on the thePath string. Then we pass that to the substring() method we call on the same thePath string. This will return a new string that starts from the position of the last / , + 1 (otherwise we’d also get the / back).

How do you split a url in node?

You can split the url string using the split() method by specifying a delimiter ( / in your case) and it will return an array.

Is WordPress a URL?

Your WordPress Address (URL) is the address where WordPress files and folders are stored including your admin pages, media files, plugins, themes, etc. Your Site Address (URL) in WordPress is the public facing part of your website. This is what your visitors will type in to reach your website.

How do I find the URL parameters in WordPress?

Getting URL Parameters by Using a Plugin

  1. Step 1: Choose a Plugin. Unfortunately, there are not many URL parameter plugins that have been well-tested with the most updated version of WordPress.
  2. Step 2: Insert the Shortcode You Want to Use. The URL Params plugin provides a shortcode that you can use on your pages and posts.

How to get the last segment of an url?

The split () method first splits the url into an array of elements separated by the / then pop () method helps us to get the last element of an array (that is our url last segment). Similarly, we can also get the last segment by using the combination of substring (), lastIndexOf () methods.

How to get the last path segment in Java?

To get the second-to-last segment while avoiding index numbers and the potential for off-by-one errors, use the getParent () method. Note the getParent () method can be called repeatedly to retrieve segments in reverse order.

How to get the last segment of Uri?

To get the last segment in one line of code, simply nest the lines above. Paths.get (URI.create (“http://base_path/some_segment/id”).getPath ()).getFileName ().toString () To get the second-to-last segment while avoiding index numbers and the potential for off-by-one errors, use the getParent () method.

What to do with the second segment of Stack Overflow?

Once you have the $currentSegment, you can echo it out or use it in an if/else or switch statement to do whatever you like based on the value of the final segment. Thanks for contributing an answer to Stack Overflow!