English,Japanese pages have been linked mutually automatically using PHP

When an English page is made, let's have them link pertinent pages that a Japanese pages and are English mutually. It becomes convenient, and I think that I become it advantageously on SEO if it does so. This was automatically done by using PHP.

Arrangement of directory on Japanese page and English page

The directory arrangement was made by thinking plainly at making an English page later so that convenience was good. In a word, URL on an English page was assumed to be the one that "" was added just behind the domain.

Only if the link is simply made, the link to the page that makes the page English is made for a Japanese page, and the link to a page Japanese, that the page and the content are the same as an English page is made inversely. With this, it is necessary to change each page in every case, and time is serious.

Then, I decided to create the link which is common to each page and can be used for a side portion. In addition, this side part is made into an external file, and is carrying out PHP include.

The link of the same content to an English page is set to a Japanese page.

If an English page of the same content did not exist at the same time as setting the link to the page and an English page of the same content to a Japanese page, the Japanese page was set and the link to the page that translated the web into English was set as follows.

if (file_exists('..'.$en_name) or file_exists('.'.$en_name)) {
echo "<a href=\"${en_name}\" title=\"English page of same content\">English version</a>\n";
else {
echo "<a href=\"//translate.google.com/translate?hl=en&amp;sl=ja&amp;tl=en&amp;u=http://hogehoge.jp${jp_name}\" title=\"Translate to English as for this page\" rel=\"external nofollow\">Translate to English</a>\n";

Here, $_SERVER['SCRIPT_NAME'] is the one that everything from URL on the page to the domain name was deleted. In a word, URL : If it is "http://hogehoge.jp/abc/nihongo.php", it becomes "/abc/nihongo.php".

To make it to English URL, it adds "/en" to this.

The link of the same content to a Japanese page is set to an English page.

The link from an English page to the page and a Japanese page of the same content was set. If a pertinent file existed, the link to the page was displayed. If the file doesn't exist, nothing is done.

if (file_exists('..'.$jp_name)) {
echo "<a href=\"${jp_name}\" title=\"Japanese Page of the same contents\">Japanese version</a>\n";

Here, "/en" is removed from "$_SERVER['SCRIPT_NAME']" by using the function of substr(). And, it is confirmed whether it goes up to the directory above one and the file exists.

PHP substr() Function

The function of substr() is to return a part of the character string.

substr(string, start, [length])

Substr() is a character string From the position specified with start of string Worth of the length byte a character string is returned. When start is positive, the returned character string is string Count from 0 It becomes a character string that starts from the start turn eyes.

When start is negative, the returned character string is counted from the back of string It becomes a character string that starts from the start turn eyes.

Automatic link result on English, Japanese page

A movement from a Japanese page to an English page and the opposite movement are very convenient. English is sure to become a popular page a popular page of SEO in Japanese.