I'm writing a function which detects a file path within a string and hyperlink it to that path, i.e: X:\test\test.gif or Z:\test etc etc which will be hyperlinked to file:///Z|test.gif. I've got the regular expression working to detect this:
Code: Select all
([a-zA-Z]):(\\([a-zA-Z0-9_ ]+))+\\?(\.([a-zA-Z0-9_]+))?Code: Select all
function autoFile($input)
{
$data = explode (" ", $input);
$output = array();
foreach ($data as $string) {
$string = addslashes(htmlspecialchars($string));
echo $string;
$output[] = preg_replace("([a-zA-Z]):(\\([a-zA-Z0-9_ ]+))+\\?(\.([a-zA-Z0-9_]+))?","<a href=\"file:///\\1\">\\1</a>", $string);
}
return implode (" ", $output);
}
echo autoFile("X:\test\test.gif");Any help will be much appreciated.
Ben