Jump to content

geomc

Newly Registered
  • Posts

    7
  • Joined

  • Last visited

geomc's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. How do you selectively BOLD output array elements from three arrays? My code has only one output line. I am creating a madlib php program and I want my nouns to be in bold, my verbs to be italicized, and my adjectives to be underlined. Where would I implement this? Thanks. Here is my code: $counter=0; $nounCounter=0; $verbCounter=0; $adjCounter=0; $newSentArray = $sentArray; // copy $sentArray while ( $counter < count($sentArray)) // loop over words in array { if($sentArray[$counter] == "NOUN" or $sentArray[$counter] == "NOUN." or $sentArray[$counter] == "NOUN!") { // replace current word with noun $newSentArray[$counter] = $nounArray[$nounCounter]; $nounCounter++; // increment noun, so next noun in used for replacement } elseif($sentArray[$counter] == "VERB" or $sentArray[$counter] == "VERB." or $sentArray[$counter] == "VERB!") { // replace current word with verb $newSentArray[$counter] = $verbArray[$verbCounter]; $verbCounter++; // increment verb, so next verb in used for replacement } elseif($sentArray[$counter] == "ADJECTIVE" or $sentArray[$counter] == "ADJECTIVE." or $sentArray[$counter] == "ADJECTIVE!") { // replace current word with adjective $newSentArray[$counter] = $adjArray[$adjCounter]; $adjCounter++; // increment adjective, so next adjective in used for replacement } $counter++; } // implode words array into a string echo implode(' ', $newSentArray);
  2. I was typing the sentence in with a period at the end like this: I bought a NOUN and a NOUN. I took out the period and now it works...Thank you so much for your help.
  3. OK, you are getting really close! I tried the two codes above and they both are giving me this now: "I bought a cat and a NOUN." The only problem I have now is getting the second NOUN to be replaced with dog. What could I fix in the code you gave me to do this? Thanks!
  4. Here is my code again if you need to see it: $counter=0; $nounCounter=0; if($sentArray[$counter]=="NOUN") { $pos = strpos($initialSent, $sentArray[$counter]); $newSent = substr_replace($initialSent, $nounArray[$nounCounter], $pos, strlen($sentArray[$counter])); echo $newSent . '<br .>';
  5. Hi, I appreciate the help. I did try this code,but now I'm getting "I bought a dog and a dog." I am sorry I am such novice on this and the problem I am having is what you described, which is having it continue from where the previous replacement happened. It's not working. Here is how I test my program, on the submit form, I select 2 nouns, I enter the nouns cat and dog where I enter the nouns. Then at the bottom I type in the initial sentence of "I bought a NOUN and a NOUN." Then I click submit. What I want the PHP code to do is replace each instance of NOUN with a different noun from the list(cat or dog). I want the final sentence to look like this: "I bought a cat and a dog." Any other help would greatly be appreciated. Thanks. Oh, and one more thing I forgot to mention, my initial sentence is exploded (sentArray) into an array and the nouns the user enters are exploded into an array(nounArray). Thanks.
  6. Can anyone help me? I am a student and I have been working on a PHP project for over two weeks with no luck on one piece of code. The project is a small "Madlib" project, but I'm only having trouble with one piece of code. Any takers? All I'm trying to do is get a sentence like "I bought a NOUN and NOUN." to be replaced with "I bought a cat and a dog." The problem is, I get this: "I bought a cat and a cat." I have tried all the loops I can try. Yes, I'm a newbie, but I'm desperate and can't figure this out. I have my html and php code, also the URL to the website. Any help would greatly be appreciated. Thanks. I have attached my html and my php file to this posting. project1.htmlproject1.php I have posted the small piece of code I am having a problem with down below: $counter=0; $nounCounter=0; while ( $counter < $sentLength and $nounCounter < $nounLength) { if($sentArray[$counter]=="NOUN") { $newSent = str_replace($sentArray[$counter], $nounArray[$nounCounter], $initialSent); } $counter++; echo $newSent . '<br .>';
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.