I tried pretty much all the methods to test if path like this file:///c:/folder/texts/int.txt
or file:///d:/folder/texts/int.txt
starts with d:/
or a:/
or c:/
somothings with string :/
some one have an idea please I try to use for this
if(strpos($URL, "c:/")) $URL = $URL;
else $URL = "http://$URL";
but it test just if the url starts with c:/
and i would like that test if it beginning with somothing like "{a,b,c,.............,z}:/"
.
How about using preg_match
with PHP
?
if (preg_match("#[a-z]:/#", $URL))
This, however, assumes that the drive can be anywhere in the string, and therefore that the path in it is a valid one. If you want it to specifically start with file///drive:/
, then use this instead:
if (preg_match("#^file///[a-z]:/#", $URL))
Use regex with this method you can check to see if a string matches a pattern, in the following code I check if the string = [a-z]://
(case insensitive). If it doesn't = that then I append c://
to the start of the string.
Change the url variable to what ever you want and run the code, it should pop-up with the url in the correct format.
var url = "working";
var re = /\w:////.*/
var x = url.search(re);
if(x != 0){
url = "c://"+url;
}
alert(url);