March 12th, 2011 03:53 AM
#1
Need help with this PHP script
I recently bought a text translation script to be embedded into a website, as I wanted a place on my site where people could translate text. Only problem is that the script cuts off text whenever punctuation is introduced, I want people to at least be able to translate entire paragraphs; not just single words or sentences. I think the problem is somewhere in the PHP code, but I can't quite seem to pin it down. Maybe someone with a little more knowledge can help me out. Here's the code:
Code:
<?php
function getstring($a,$b,$c){
$y = explode($b,$a);
$x = explode($c,$y[1]);
return $x[0];
}
// Check if form has been submitted
if($_REQUEST['txt']){
ini_set("max_execution_time", 0); // no time-outs!
ignore_user_abort(true); // Continue downloading even after user closes the browser.
//$text = stripslashes($_REQUEST['txt']);
$text = $_REQUEST['txt'];
//$text = str_replace(' ', '+', $text);
$lang1 = $_REQUEST['lang1'];
$lang2 = $_REQUEST['lang2'];
echo translate($text,$lang1,$lang2);
}
else { echo "<center>You can't access this file directly! redirecting to home page now.</center>";
?><meta http-equiv="REFRESH" content="3;url=index.php"><?
exit;}
function translate($text,$lang1,$lang2){
$query = "js=n&prev=_t&hl=en&ie=UTF-8&text=$text&file=&sl=$lang1&tl=$lang2";
$ch=curl_init();
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_URL, "http://translate.google.com/?");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_ENCODING , "UTF-8");
$output = curl_exec($ch);
// echo $output;
curl_close($ch);
if ($lang2=="ar" || $lang2=="iw") {
$body = getstring($output, "overflow:auto\">", "</textarea></div>");
if ($body==""){
$body = getstring($output, "'#fff'\">", "</span></span></div>");
}
$prefix="<br><br>";
$body=$prefix.$body;
return $body;
//return $output;
}
if ($lang2=="fr") {
$body = getstring($output, "overflow:auto\">", "</textarea></div>");
if ($body==""){
$body = getstring($output, "'#fff'\">", "</span></span></div>");
}
$prefix="<br><br>";
$body=$prefix.$body;
//return $output;
$body = str_replace('&#39;', "'", $body);
return str_replace("é", "é", $body);
}
else {
$body = getstring($output, "overflow:auto\">", "</textarea></div>");
if ($body==""){
$body = getstring($output, "'#fff'\">", "</span></span></div>");
}
$prefix="<br><br>";
$body=$prefix.$body;
return str_replace("é", "é", $body);
//return $output;
}
}
?>
March 12th, 2011 09:41 AM
#2
Re: Need help with this PHP script
Always contact the original author of any script. He/she won't need to take time to investigate the code first because he/she already wrote it.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
March 12th, 2011 01:27 PM
#3
Re: Need help with this PHP script
Already tried that. The website that sold it to me wasn't even the original creator. Thanks!
April 16th, 2011 05:03 AM
#4
Re: Need help with this PHP script
the information you have given us is of no help, you should have other files with it, you will have to speak to the person, or get a new one, or maybe try getting a free one?
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width
Bookmarks