Beispiel #1
0
            $d[$k] = utf8ize($v);
        }
    } else {
        if (is_string($d)) {
            return utf8_encode($d);
        }
    }
    return $d;
}
$finfo = null;
foreach ($array as &$search) {
    if ($search[1] == $from) {
        $finfo = $search;
        break;
    }
}
if (urlOk("http://" . $from . ".wikipedia.org/wiki/" . str_replace(" ", "_", $word) . $finfo[2]) || strcmp($finfo[2], "") == 0) {
    $html = file_get_html("http://" . $from . ".wikipedia.org/wiki/" . str_replace(" ", "_", $word) . $finfo[2]);
    $ret = $html->find('div[id=mw-content-text]');
    echo $ret[0]->innertext;
} else {
    $host = $_SERVER['HTTP_HOST'];
    $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $extra = 'stage3.php?t=' . $to . '&f=' . $from . '&w=' . str_replace(" ", "_", $word);
    header("Location: http://{$host}{$uri}/{$extra}");
}
echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>';
echo '<script src="stage2.js"></script>';
echo '<span style="display: none;" id = "to">' . $to . '</span>';
echo '<span style="display: none;" id = "from">' . $from . '</span>';
echo '<span style="display: none;" id = "array">' . json_encode(utf8ize($array)) . '</span>';
Beispiel #2
0
<?php

$to = $_GET["t"];
$from = $_GET["f"];
$word = $_GET["w"];
echo '<link rel="stylesheet" type="text/css" href="style.css">';
//mb_internal_encoding("UTF-8");
include 'array.php';
include 'simple_html_dom.php';
function urlOk($url)
{
    return filter_var($url, FILTER_VALIDATE_URL);
}
if (urlOk("http://" . $from . ".wikipedia.org/wiki/" . $word)) {
    $html = file_get_html("http://" . $from . ".wikipedia.org/wiki/" . $word);
    $ret = $html->find('li[class=interwiki-' . $to . ']');
    if ($ret != null) {
        echo " <meta charset='UTF-8'>";
        $ret = $ret[0]->find('a');
        $html = file_get_html("http:" . $ret[0]->href);
        $ret = $html->find('h1[id=firstHeading]');
        //print_r(preg_replace("/\([^)]+\)/","",$ret[0]));
        //$ret = $ret[0]->find('span');
        echo preg_replace("/\\([^)]+\\)/", "", $ret[0]);
    } else {
        echo "Sorry, could not find a translation for the requested language";
    }
} else {
    echo "Sorry, can not find word.";
}
echo "<br><br><a href='wikitranslate.php'> Return Home </a>";