Skip to main content

Posts

Showing posts with the label url

Validating URL in Java

I wanted to know if there is any standard APIs in Java to validate a given URL? I want to check both if the URL string is right i.e. the given protocol is valid and then to check if a connection can be established.

best way to determine if a URL is an image in PHP

Using PHP, given a URL, how can I determine whether it is an image? There is no context for the URL - it is just in the middle of a plain text file, or maybe just a string on its own. I don't want high overhead (e.g. reading the content of the URL) as this could be called for many URLs on a page. Given this restriction, it isn't essential that all images are identified, but I would like a fairly good guess. At the moment I am just looking at the file extension, but it feels like there should be a better way than this. Here is what I currently have: function isImage( $url ) { $pos = strrpos( $url, "."); if ($pos === false) return false; $ext = strtolower(trim(substr( $url, $pos))); $imgExts = array(".gif", ".jpg", ".jpeg", ".png", ".tiff", ".tif"); // this is far from complete but that's always going to be the case... if ( in_array($ext, $imgExts) )

Replace URLs in text with HTML links

Here is a design though: For example is I put a link such as http://example.com in textarea . How do I get PHP to detect it’s a http:// link and then print it as print "<a href='htttp://example.com'>http://example.com</a>"; I remember doing something like this before however, it was not fool proof it kept breaking for complex links. Another good idea would be if you have a link such as http://example.com/test.php?val1=bla&val2blablabla%20bla%20bla.bl fix it so it does print "<a href='http://example.com/test.php?val1=bla&val2=bla%20bla%20bla.bla'>"; print "http://example.com/test.php"; print "</a>"; This one is just an after thought.. stackoverflow could also probably use this as well :D Any Ideas Source: Tips4all

Check if URL is valid in Android without catching Exception?

See, I have to check like 50+ URLs for validity, and I'm assuming that catching more than 50 exceptions is kind of over the top. Is there a way to check if a bunch of URLs are valid without wrapping it in a try catch to catch exceptions? Also, just fyi, in Android the class "UrlValidator" doesn't exist (but it does exist in the standard java), and there's UrlUtil.isValidUrl(String url) but that method seems to be pleased with whatever you throw at it as long as it contains http://... any suggestions?

process PHP on hitting URL & configuring PHP

For my website, I want one of my PHP script to be executed on entering on URL before loading the page(before entering into my site, on hitting enter first this has to be executed), could you suggest me how. Secondly, I've configured PHP ini in localhost in order to include URL & fopen but how can I do changes on the server, am using filezilla on windows.

How do I remove the root element of my Jetty webapp url?

I am running a Java webapp (let's call it mywebapp). Currently I access my page in this webapp by pointing locally to: http://localhost:9000/mywebapp/mystuff However, I need to access it using: http://localhost:9000/mystuff How can I do this? I've tried messing with some confs, but to no avail... This is my current root.xml: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> <Configure class="org.mortbay.jetty.webapp.WebAppContext"> <Set name="contextPath">/root</Set> <Set name="war"> <SystemProperty name="app.webapps.path"/>/mywebapp.war </Set> </Configure> Also tried: <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configu