Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,483 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,738 people online right now. Registration is fast and FREE... Join Now!




Convert all text to piglatin/pirate

 
Reply to this topicStart new topic

Convert all text to piglatin/pirate, Convert all the text on the page to Pig Latin or Pirate.

dawmail333
3 Mar, 2008 - 11:41 PM
Post #1

D.I.C Head
Group Icon

Joined: 2 Jul, 2007
Posts: 50


Dream Kudos: 100
My Contributions
Quite an unusual request I imagine.

Pretty much, I'm planning to set it up so that on the 1st of April, anyone visiting my site will have it all translated to Pig Latin (and if they click a link, they escape it)), and on the 19th of September pirate.gif , the page gets translated into pirate. I can handle the pirate translation, indeed the only thing I CAN'T do is change all the visible text (and visible text ONLY) by putting it through a function. Here's a pig latin class (from this Martyr2!)

php

<?php

function translate($strTranslate) {
// Split the phrase into words
$pieces = explode(" ", $strTranslate);

// Loop through each word for translation
for ($i = 0; $i < count($pieces); $i++) {
pigLatin($pieces[$i]);
}
}

// Controller function for determining if word starts with vowel, then add "way"
// Otherwise, pass it on for rotation and add "ay"
// Piglatin has variations in rules, this is a common form but not only form.

function pigLatin($word) {
if (isVowel(substr($word,0,1))) {
echo "$word" . "way ";
}
else {
echo moveLetter($word) . "ay ";
}
}

// Recursive function to take off a non vowel letter and put it on the end
// Recall the function until a vowel is encountered and then return the word.
function moveLetter(&$word) {
if (!isVowel(substr($word,0,1))) {
$chLetter = strtolower(substr($word,0,1));
$word = substr($word,1) . $chLetter;
return moveLetter($word);
}
else { return $word; }
}

// Simply checks if letter is a vowel.
// For most pig latin variations, Y is considered a vowel.
function isVowel($chLetter) {
$letters = array("a","e","i","o","u","y");

for ($i = 0; $i < 6; $i++) {
if (strtolower($chLetter) == $letters[$i]) { return true; }
}

return false;
}

translate("This is a test");


So, can anyone help me? I can handle the execution and everything else.

Thanks in advance.

P.S. When is International Talk Like a Ninja Day?
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Convert All Text To Piglatin/pirate
4 Mar, 2008 - 04:26 AM
Post #2

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

"I CAN'T do is change all the visible text (and visible text ONLY)"

not sure i understand, how is visible text displayed and what is done with it after?


User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Convert All Text To Piglatin/pirate
4 Mar, 2008 - 04:34 AM
Post #3

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

maybe?
php

<?php

function translate($strTranslate) {
// Split the phrase into words
$pieces = explode(" ", $strTranslate);

// Loop through each word for translation
for ($i = 0; $i < count($pieces); $i++) {
$tmp .= pigLatin($pieces[$i]);
}
return($tmp);
}

// Controller function for determining if word starts with vowel, then add "way"
// Otherwise, pass it on for rotation and add "ay"
// Piglatin has variations in rules, this is a common form but not only form.

function pigLatin($word) {
if (isVowel(substr($word,0,1))) {
return "$word" . "way ";
}
else {
return moveLetter($word) . "ay ";
}
}

// Recursive function to take off a non vowel letter and put it on the end
// Recall the function until a vowel is encountered and then return the word.
function moveLetter(&$word) {
if (!isVowel(substr($word,0,1))) {
$chLetter = strtolower(substr($word,0,1));
$word = substr($word,1) . $chLetter;
return moveLetter($word);
}
else { return $word; }
}

// Simply checks if letter is a vowel.
// For most pig latin variations, Y is considered a vowel.
function isVowel($chLetter) {
$letters = array("a","e","i","o","u","y");
if (in_array(strtolower($chLetter),$letters)) { return true; }
return false;
}

$text = "This is a test";

$temp_text = translate($text);

echo ' '.$text.'<br>';

echo ' '.$temp_text.'<br>';


?>

User is offlineProfile CardPM
+Quote Post

dawmail333
RE: Convert All Text To Piglatin/pirate
4 Mar, 2008 - 10:45 PM
Post #4

D.I.C Head
Group Icon

Joined: 2 Jul, 2007
Posts: 50


Dream Kudos: 100
My Contributions
Okay, this should give you an idea:

I have a page like yay:

php

Foobar, foo + bar
<?php echo 'food';
$foobar = 'foo'; ?>


Now the code (assuming you could see php) would look like this AFTER it:

php

oobarFay, oofay, arbay
<?php echo 'food';
$foobar = 'foo'; ?>


Is this possible? I have the Pig Latin function, I just need it to apply to all WRITTEN & VISIBLE text on the page.
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Convert All Text To Piglatin/pirate
5 Mar, 2008 - 09:32 AM
Post #5

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

from what i understand, i did this.
you have the original text and pigy text each in their own strings.

or i not getting what you are trying to say.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:06PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month