开发者

When moving a folder in the server, correct all links

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.

开发者_Go百科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.

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


$sampleLink = "books/book1.php";

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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜