Note that there are some explanatory texts on larger screens.

plurals
  1. PONested conditional using radio buttons to guide script in PHP
    primarykey
    data
    text
    <p>I've been working on this for a while and I can't seem to figure it out. I know it must be something really simple. Basically I have a script that works as a program that translates English to Piglatin, and it works fine, but I want the user to have a choice of whether or not to actually operate that script, by using a radio form with the text input that says "English" or "Piglatin". I've tried all different ways to get this to work, but using a nested conditional seems like it would be the most logical answer to me. However, whenever I try to run the script with it, it doesn't work. Can someone please tell me what I'm doing wrong?! It would be much appreciated. Thanks!</p> <p>HTML Form:</p> <pre><code>&lt;p&gt;&lt;input type="text" name="original" size="20" maxlength="40" /&gt;&lt;/label&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="radio" name="english" value="yes"/&gt;english &lt;input type="radio" name="english" value="no"/&gt;piglatin&lt;/p&gt; &lt;input type="submit" name="submit" value="submit" /&gt;&lt;/form&gt; </code></pre> <p>PHP:</p> <pre><code>&lt;?php # script $original = $_REQUEST['original']; $english = $_REQUEST['english']; $array = explode(" ", $original); if($english=="no") { piglatin = ""; foreach($array as $word) { $word = trim($word); $first = substr($word,0,1); $rest = substr($word,1,strlen($word)-1); if (preg_match('/^[aeiou]/', $word)) { $word = preg_replace('/^([aeiou].+)$/', "$1-way", $word); } elseif (preg_match('/^(th|sh)/', $word)) { $word = preg_replace('/^(th|sh)(.+)$/', "$2-$1ay", $word); } else { $word = preg_replace('/^[a-z](.+)$/', "$1-$first"."ay", $word); } $piglatin .= $word ." "; echo $original ." becomes: ".$piglatin."."; }; else {echo $original."."; }; ?&gt; </code></pre> <p>Like I said, I'm sure it's something really small and simple that I just can't see because I've been looking at the code so long. Any help is appreciated! Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload