using 'preg_replace' in php wiki

I am trying to format a wiki hyperlink to a local word document.

The location of the document is for example at:
\\testserver\general\test_House\SCM-Deliver\this_is_a_test.doc

How can I format this using 'preg_replace'. Something similar to the code below

// Prepare page formatting
    elseif ($action <> "edit") {
        $CONTENT = htmlentities($CONTENT);
            $CONTENT = preg_replace("/&amp;#036;/Umsi", "&#036;", $CONTENT);
            $CONTENT = preg_replace('#\[(.+)\|h(ttps?://[0-9a-zA-Z\.\#/~\-_%=\?\&amp;,\+]*)\]#U', '<a href="xx$2">$1</a>', $CONTENT);
            $CONTENT = preg_replace('#h(ttps?://[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*\.(jpg|gif|png))#i', '<img src="xx$1" />', $CONTENT);
            $CONTENT = preg_replace('#(https?://[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*)#i', '<a href="$0">$1</a>', $CONTENT);
            $CONTENT = preg_replace('#(file?:///[0-9a-zA-Z\.\&amp;\#\:/~\-_%=?]*)#i', '<a href="$0">$1</a>', $CONTENT);
            $CONTENT = preg_replace('#xxttp#', 'http', $CONTENT);
            
The above is used for ordinary http links.

Any suggestions?
dansker69Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

b0lsc0ttIT ManagerCommented:
dansker69,

You won't be able to use that same path in your html and have it resolve.  In other words \\testserver\..... doesn't mean anything on your user's computer in his browser.  In fact browser security would stop it from working even if he had a share called testserver.

What type of tag or element should be used (e.g. anchor, image)?  What is the URL for that DNC path?  If the web user won't have direct access to it then you need to use some server page to get the file.

Let me know if you have any questions or need more information.

b0lsc0tt
0
dansker69Author Commented:
I was looking at something similar to:
$CONTENT = preg_replace("/\@([0-9a-zA-Z\- :\.,\(\)\']+)\@/U", '<a href="file://ftr245/general/In_House/$1">$1</a>', $CONTENT);

Placing a filename between the @ @ gives me a usable link, but only to 'In_House' folder.

I need a variable simliar to $1, which will accept a folder name and a filename
folder = XX file=YY, such as @xx,yy@. This will be used on an intranet.
0
b0lsc0ttIT ManagerCommented:
How well this would work would really depend on the content but a basic expression that will get the folder(s) and name from between @'s is ...

@(.+\\)([^\\]+)@

The first group would be the folders and the second group the file name.  For example with ...

@test_House\SCM-Deliver\this_is_a_test.doc@

... the result is ...

$1 is test_House\SCM-Deliver\
$2 is this_is_a_test.doc

Let me know how this helps or if you have a question.

bol
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

ddrudikCommented:
There's a number of possible ways to do this, here's one:
<?php
$sourcestring='this is a test @testserver\general\test_House\SCM-Deliver\this_is_a_test.doc@ for preg_replace';
echo preg_replace('/@(.*?)@/e','str_replace(chr(92),"/","<a href=\"file://$1\">$1</a>")',$sourcestring);
?>

Open in new window

0
dansker69Author Commented:
The solutions up to now are partially correct. To better explain the problem.
Anything between @@@     @@@

@@@Link Text|\\testserver\SCM-Deliver\this_is_a_test.doc@@@
needs to be preg_replaced with
<a href=\"file://testserver\SCM-Deliver\this_is_a_test.doc">Alias Link Text</a>

Does this help clarify the problem?
0
ddrudikCommented:
Consider this code (I escaped the double \ in your source string with \'s so that PHP would consider them two literal slashes instead of one):
<?php
$sourcestring='test @@@Link Text|\\\\testserver\SCM-Deliver\this_is_a_test.doc@@@ test';
echo preg_replace('/@@@([^@]*)\|([^@]*)@@@/se','str_replace(chr(92),"/","<a href=\"file:$2\">$1</a>")',$sourcestring);
?>

Open in new window

0
dansker69Author Commented:
The above does not work. The output of anything between the two @@@, should be a hyperlink.
@@@Link Text|\\testserver\SCM-Deliver\this_is_a_test.doc@@@

Where @@@Link Text| is the Link text and
|\\testserver\SCM-Deliver\this_is_a_test.doc@@@ is the link itself.
0
ddrudikCommented:
dansker69, show a specific example that you would like me to follow, your example in post 20947040 would not work because the file:// requires all following slashes to be forward slashes instead of backslashes as in your example.

ref:
http://en.wikipedia.org/wiki/File:_URL

Output of my script from post 20947780:
test <a href="file://testserver/SCM-Deliver/this_is_a_test.doc">Link Text</a> test
0
ddrudikCommented:
From the wiki page it noted that file:// URL's that use network shares should be in the format of file:////server/file:
<?php
$sourcestring='test @@@Link Text|\\\\testserver\SCM-Deliver\this_is_a_test.doc@@@ test';
echo preg_replace('/@@@([^@]*)\|([^@]*)@@@/se','str_replace(chr(92),"/","<a href=\"file://$2\">$1</a>")',$sourcestring);
?>
Does that work?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dansker69Author Commented:
This works perfectly.
0
ddrudikCommented:
Thanks for the question and the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.