Unstoppable Domains

Need PHP Piglatin script

Spaceship Spaceship
Watch
Impact
98
English to Piglatin translator needed.

I want to have a piglatin script that you can enter text in a comment and have it translate it from English to Piglatin.

I have found one but it reads from a text file and writes to a text file.

I was hoping someone could edit this and have it read from the textbox and display on the screen.

I also want a couple other mods but this is a start.

I will pay for someone to complete this.

Extra - If you know how to do a Piglatin to English translator script that would be helpful too.


PHP:
piglatin.php code

 

#!/usr/local/bin/php
<?php
/* This program translates one line of text in a file called oneline to pig latin. */
/* It includes examples of reading from files, defining functions, associative arrays */
/* and string functions. */
/* The rotate function shifts the charaters in a string one position to the left  */
/* bringing the first character around to the end of the string */
function rotate($a)
  {
  $rotatedstring = substr($a,1,strlen($a)-1).substr($a,0,1);
  return $rotatedstring;
  }
/* The alphabet array is an associative array with the index being the letter and */
/* the value being either "vowel" or "consonant."  */
$alphabet=array(
  'a'=>"vowel",
  'b'=>"consonant",
  'c'=>"consonant",
  'd'=>"consonant",
  'e'=>"vowel",
  'f'=>"consonant",
  'g'=>"consonant",
  'h'=>"consonant",
  'i'=>"vowel",
  'j'=>"consonant",
  'k'=>"consonant",
  'l'=>"consonant",
  'm'=>"consonant",
  'n'=>"consonant",
  'o'=>"vowel",
  'p'=>"consonant",
  'q'=>"consonant",
  'r'=>"consonant",
  's'=>"consonant",
  't'=>"consonant",
  'u'=>"vowel",
  'v'=>"consonant",
  'w'=>"consonant",
  'x'=>"consonant",
  'y'=>"consonant",
  'z'=>"consonant"
);
$fp=fopen($_GET['fname'],"r");
$line=fgets($fp,1024);
print "<html><h2>Original Line of Text: </h2>".$line."<p>";
/* Break string into words with explode */
$words=explode(" ",$line);
$index=0;
/* Run thru each word in array */
foreach ($words as $word)
  {
  $tword=trim($word);
  $word=$tword;
  $first=substr($word,0,1);
  if ($alphabet[$first]=="vowel")
    {
    $pig=$word."way";
/*  This word began with a vowel so we're done.  */
    }
  else
    {
    $pig=rotate($word);
    $word=$pig;
    $first=substr($word,0,1);
/* Rotate string until we get to a vowel  */
    while ($alphabet[$first]=="consonant") 
     {
     $pig=rotate($word); 
     $word=$pig;
     $first=substr($word,0,1);
      } 
    $pig=$word."ay"; 
    } 
  $pigword[$index]=$pig;
  $index=$index+1;
  }
/* Now implode the words back together */
$piglatin=implode(" ",$pigword);

print "<h2>In Pig Latin: </h2>".$piglatin;
print "</html>";
?>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
Still need help with this. If you have another script that will work too. Let me know your price.
 
0
•••
Join Live Chat and contact me now if you want help, I'm happy to go through this with you.
 
0
•••
Thanks, I am mainly just looking for someone to enter a chunk of text into a textbox and have a button that says convert to piglatin and it will convert it to piglatin.
 
0
•••
Didn't change the original coding much.

PHP:
<?php

if (!isset($_POST['s']))
{
?>
	<form method="POST" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
		<input type="text" name="line" size=40 />
		<input type="submit" name="s" value="Pig Latinify" />
	</form>
	<?php

}
else
{

    function rotate($a)
    {
        $rotatedstring = substr($a, 1, strlen($a) - 1) . substr($a, 0, 1);
        return $rotatedstring;
    }

    $alphabet = array('a' => "v", 'b' => "c", 'c' => "c", 'd' => "c", 'e' => "v",
        'f' => "c", 'g' => "c", 'h' => "c", 'i' => "v", 'j' => "c", 'k' => "c", 'l' =>
        "c", 'm' => "c", 'n' => "c", 'o' => "v", 'p' => "c", 'q' => "c", 'r' => "c", 's' =>
        "c", 't' => "c", 'u' => "v", 'v' => "c", 'w' => "c", 'x' => "c", 'y' => "c", 'z' =>
        "c");

    $line = (get_magic_quotes_gpc()) ? stripslashes($_POST['line']) : $_POST['line'];

    print '<html><h2>Original Line of Text: </h2>' . $line . '<p>';

    $words = explode(' ', $line);
    $index = 0;

    foreach ($words as $word)
    {
        $tword = trim($word);
        $word = $tword;
        $first = substr($word, 0, 1);
        if ($alphabet[$first] == 'v')
        {
            $pig = $word . 'way';

        }
        else
        {
            $pig = rotate($word);
            $word = $pig;
            $first = substr($word, 0, 1);

            while ($alphabet[$first] == 'c')
            {
                $pig = rotate($word);
                $word = $pig;
                $first = substr($word, 0, 1);
            }
            $pig = $word . 'ay';
        }
        $pigword[$index] = $pig;
        $index = $index + 1;
    }

    $piglatin = implode(' ', $pigword);

    echo '<h2>In Pig Latin: </h2>' . ucwords(strtolower($piglatin));
    echo '</html>';

}
?>
 
0
•••
Would it be possible to use <textarea cols="64" rows="10" name="line"></textarea><br /><br /> instead? I tried but it keeps timing out. I think it needs to get rid of newlines or something.
 
0
•••
Yes, obviously.

PHP doesn't know where the variable comes from in the first place, if it's a textarea, PHP can't tell the difference between that and a input box.

Dan
 
0
•••
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back