views:

10

answers:

2

Lets say I have this folder on my server called books.

Inside I have and index.php with this links: books/book1.php books/book2.php

I then decide to create a subdirectory called "scifi", for a better sorting of the books.

So the books are no in: books/scifi/book1.php books/scifi/book2.php

The links have changed and now the links on index.php dont work.

How can I (or redirect*) all the links without having to go one by one

Thanks in advance!!

*please dont be thrown away by redirect I do not mean it in the programming way (necessarily) rather in an illustrative one.

+1  A: 
$sampleLink = "books/book1.php";

$temp = explode("/",$sampleLink);  //["books","book1.php"]
$temp[0] .= "/scifi";  //["books/scifi","book1.php"]
$sampleLink = implode("/",$temp);  //"books/scifi/book1.php"
Steve
I´m taking a look, thanks!
Trufa
@Steve I dont understand how I actually get it to work
Trufa
@Steve What I mean is should and how do I assign the variables you defined to the links
Trufa
A: 

Just to clarify Steve´s answer:

<?php

$sampleLink = '<a href="/book1.php">Book...</a>';

$temp = explode("/",$sampleLink);  //["books","book1.php"]
$temp[0] .= "/email/books/scifi";  //["books/scifi","book1.php"]
$sampleLink = implode("/",$temp);  //"books/scifi/book1.php"

echo $sampleLink;
?>

It was really useful as a lesson but i didn´t have the links links defined as php variables so the work would be the same!

Thanks you very much!

Trufa
No worries mate. Yep that would work too. Wasn't quite sure what you wanted since no code sample...
Steve