Jump to content

weird str_replace need


jandrews3

Recommended Posts

I need to be able to remove "Yo ", "yo ", "Tú ", "tú ", "Nosotros ", "nosotros " from a string and then test the string against the correct answer in my database (I'm a teacher). I thought the following would work:

$remove = array("Yo ", "yo ", "Tú ", "tú ", "Nosotros ", "nosotros ");
if (ucfirst(str_replace($remove,"",$ans1)) == $dba1)	 {$stat1 = 1; $correct++;} else {$missed++; $stat1 = 0;}

The ucfirst is to make sure the first letter of the string is capitalized in case the removed word had been first.

 

It works for Yo, yo, Nosotros and nosotros; but not for Tú or tú. The reason appears to be that the str_replace doesn't recognize that the user input "Tú" is the same as the $remove variable's "Tú" value. Is there a fix to this. Thanks.

 

I also tried it this way without any success:

$remove = array("Yo ", "yo ", "Tú ", "tú ", "Nosotros ", "nosotros ");

Link to comment
https://forums.phpfreaks.com/topic/188790-weird-str_replace-need/
Share on other sites

It's a regular form posting from quiz_take.php to quiz_grade.php page. I need the str_replace to remove occurrences of "Yo ", "yo ", "Tú ", "tú ", "Nosotros ", "nosotros ". I can get it to work with all but "Tú " and "tú ". As far as encoding goes, I'm not sure what you mean. I'm still pretty much an amateur. It's a simple form submission. I tried the str_replace with "Tú " and "tú " but to no avail.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.