Get Last Part of URL PHP

The absolute simplest way to accomplish this, is with basename() echo basename(‘http://domain.com/artist/song/music-videos/song-title/9393903’); Which will print 9393903 Of course, if there is a query string at the end it will be included in the returned value, in which case the accepted answer is a better solution.

How do I parse a URL query parameters, in Javascript? [duplicate]

Today (2.5 years after this answer) you can safely use Array.forEach. As @ricosrealm suggests, decodeURIComponent was used in this function. function getJsonFromUrl(url) { if(!url) url = location.search; var query = url.substr(1); var result = {}; query.split(“&”).forEach(function(part) { var item = part.split(“=”); result[item[0]] = decodeURIComponent(item[1]); }); return result; } actually it’s not that simple, see the … Read more

URL query parameters to dict python

Use the urllib.parse library: >>> from urllib import parse >>> url = “http://www.example.org/default.html?ct=32&op=92&item=98″ >>> parse.urlsplit(url) SplitResult(scheme=”http”, netloc=”www.example.org”, path=”/default.html”, query=’ct=32&op=92&item=98′, fragment=””) >>> parse.parse_qs(parse.urlsplit(url).query) {‘item’: [’98’], ‘op’: [’92’], ‘ct’: [’32’]} >>> dict(parse.parse_qsl(parse.urlsplit(url).query)) {‘item’: ’98’, ‘op’: ’92’, ‘ct’: ’32’} The urllib.parse.parse_qs() and urllib.parse.parse_qsl() methods parse out query strings, taking into account that keys can occur more than once … Read more

How do I make an http request using cookies on Android?

It turns out that Google Android ships with Apache HttpClient 4.0, and I was able to figure out how to do it using the “Form based logon” example in the HttpClient docs: https://github.com/apache/httpcomponents-client/blob/master/httpclient5/src/test/java/org/apache/hc/client5/http/examples/ClientFormLogin.java import java.util.ArrayList; import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.cookie.Cookie; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.message.BasicNameValuePair; … Read more

Validating URL in Java

For the benefit of the community, since this thread is top on Google when searching for “url validator java“ Catching exceptions is expensive, and should be avoided when possible. If you just want to verify your String is a valid URL, you can use the UrlValidator class from the Apache Commons Validator project. For example: … Read more