Forum Moderators: coopster

Message Too Old, No Replies

modif an array output

how to

         

henry0

7:01 pm on Sep 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If I query $url
and explode it
$link=explode(" ",$url);
and then if I test $link by using: echo $link[1];
the result is: href="index.php">Home
instead of <a href="index.php">Home</a>
so no "<a" and "</a>" are showing
why is that? perhaps due to html tags not showing but if it is why would I get "> at the end of index.php

Next I need to modif the output in order to obtain ../index.php instead of index.php
(I just need to modif the output not the DB)

how should I do it?

ergophobe

10:28 pm on Sep 8, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If your link is


<a href="index.php">Home</a>

and you explode on a space, the
$arr[0] = '<a';
$arr[1] = 'href="index.php">Home</a>';

So the first part is expected, but the second isn't. Are you certain there are no spaces in your input after "Home"?

How about something like

$relative_path = preg_replace('/<a.*href="([^"])/U', '../$1', $url);

henry0

1:30 pm on Sep 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thank you
You were correct an "invader" extra space was there

Appreciated the preg_replace
I know that I definitely got to pay attention at this part of my coding.