NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Need PHP Piglatin script

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 10-14-2007, 08:42 PM THREAD STARTER               #1 (permalink)
jdk
Senior Member
 
jdk's Avatar
Join Date: Jul 2004
Location: Florida
Posts: 1,496
jdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond repute
 



Need PHP Piglatin script


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 Code:
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",
????: NamePros.com http://www.namepros.com/programming/384853-need-php-piglatin-script.html
  
'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);
????: NamePros.com http://www.namepros.com/showthread.php?t=384853

print 
"<h2>In Pig Latin: </h2>".$piglatin;
print 
"</html>";
?>
jdk is offline  
Old 02-06-2008, 10:47 AM THREAD STARTER               #2 (permalink)
jdk
Senior Member
 
jdk's Avatar
Join Date: Jul 2004
Location: Florida
Posts: 1,496
jdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond repute
 



Still need help with this. If you have another script that will work too. Let me know your price.
jdk is offline  
Old 02-06-2008, 11:03 AM   #3 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
Join Live Chat and contact me now if you want help, I'm happy to go through this with you.
Daniel is offline  
Old 02-06-2008, 11:09 AM THREAD STARTER               #4 (permalink)
jdk
Senior Member
 
jdk's Avatar
Join Date: Jul 2004
Location: Florida
Posts: 1,496
jdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond repute
 



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.
jdk is offline  
Old 02-06-2008, 11:19 AM   #5 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
Didn't change the original coding much.

PHP Code:
<?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($a1strlen($a) - 1) . substr($a01);
        return 
$rotatedstring;
    }

    
$alphabet = array('a' => "v"'b' => "c"'c' => "c"'d' => "c"'e' => "v",
????: NamePros.com http://www.namepros.com/showthread.php?t=384853
        
'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' =>
????: NamePros.com http://www.namepros.com/showthread.php?t=384853
        
"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($word01);
        if (
$alphabet[$first] == 'v')
        {
            
$pig $word 'way';

        }
        else
        {
            
$pig rotate($word);
            
$word $pig;
            
$first substr($word01);

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

    
$piglatin implode(' '$pigword);

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

}
?>
Daniel is offline  
Old 02-06-2008, 11:42 AM THREAD STARTER               #6 (permalink)
jdk
Senior Member
 
jdk's Avatar
Join Date: Jul 2004
Location: Florida
Posts: 1,496
jdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond reputejdk has a reputation beyond repute
 



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.
jdk is offline  
Old 02-07-2008, 01:48 AM   #7 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
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
Daniel is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 02:25 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger