function returnSubstrings($text, $openingMarker, $closingMarker) {
$openingMarkerLength = strlen($openingMarker);
$closingMarkerLength = strlen($closingMarker);
$result = array();
$position = 0;
while (($position = strpos($text, $openingMarker, $position)) !== false) {
$position += $openingMarkerLength;
if (($closingMarkerPosition = strpos($text, $closingMarker, $position)) !== false) {
$result[] = substr($text, $position, $closingMarkerPosition - $position);
$position = $closingMarkerPosition + $closingMarkerLength;
}
}
return $result;
}
function flags(){
global $site_url, $lang, $url;
$img_path = "http://".$site_url."/websitetranslator/";
$flag = '
website translator
';
return $flag;
}
function curlPageSystran() {
global $lang, $site_url, $url, $args;
$str = array(
"Accept-Language: en-us,en;q=0.5",
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
"Keep-Alive: 300",
"Connection: keep-alive"
);
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_HTTPHEADER, $str);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"systran_lp=en_".$lang."&systran_id=http://www.appliedlanguage.com/&systran_url=http://".$site_url."/".$url.$args);
curl_setopt($ch, CURLOPT_URL,"http://www.systranlinks.com/trans");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page=curl_exec($ch);
curl_close($ch);
return $page ;
}
function curlPageGoogle() {
global $lang, $site_url, $url, $args;
$str = array(
"Accept-Language: en-us,en;q=0.5",
"Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7",
"Keep-Alive: 300",
"Connection: keep-alive"
);
$ch = curl_init() or die(curl_error());
curl_setopt($ch, CURLOPT_HTTPHEADER, $str);
curl_setopt($ch, CURLOPT_URL,"http://translate.google.com/translate?hl=en&sl=en&tl=".$lang."&u=http://".$site_url."/".$url.$args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$page=curl_exec($ch);
/* Find the non-framed URL and get it */
if(preg_match('|location="(/translate_p.*?)";|', $page, $matches)) {
$url2 = $matches[1];
$url2 = preg_replace("/&/", "&", $url2);
curl_setopt($ch, CURLOPT_URL, "http://translate.google.com$url2");
$page=curl_exec($ch);
if(preg_match('|a href="(http://[0-9].*?translate_c.*?)"|', $page, $matches)) {
$url3 = $matches[1];
$url3 = preg_replace("/&/", "&", $url3);
curl_setopt($ch, CURLOPT_URL, $url3);
$page=curl_exec($ch);
} else {
echo "Translation Error.";
}
} else {
echo "Translation Error.";
}
curl_close($ch);
return $page;
}
?>