thebobby Posted April 10, 2012 Posted April 10, 2012 $subject = str_replace("\\", "\\\\", htmlspecialchars($_POST['subject'], ENT_QUOTES )); $subject = str_replace("yahoo", " ", htmlspecialchars($_POST['subject'], ENT_QUOTES )); $msgtext = str_replace(".yahoo", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $send_person = new User($to); this works if yahoo is wrote in message box it changes to goolge. But want i want is to be able to add more. Like this: $subject = str_replace("\\", "\\\\", htmlspecialchars($_POST['subject'], ENT_QUOTES )); $subject = str_replace("yahoo", " ", htmlspecialchars($_POST['subject'], ENT_QUOTES )); $msgtext = str_replace(".yahoo", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $msgtext = str_replace(".ebay", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $msgtext = str_replace(".coke", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $msgtext = str_replace(".green", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); and when i add more like that it only does the bottom one not the others... so anybody know how i can write the code so i can have muiltiple words. Wats this does is it replace the first word and makes it google. these words are examples Quote
Djkanna Posted April 10, 2012 Posted April 10, 2012 (edited) Use an array. :) Edit: To be helpful, an example of a way you could do it. function replaceWords($text) { $words = array ( 'Google' => 'Yahoo', 'Bing' => 'Duck Duck Go', 'AltaVista' => 'AWWWWW YEAAAAAAH' ); $replaced = str_ireplace(array_keys($words), array_values($words), $text); return htmlentities($replaced, ENT_QUOTES, 'UTF-8'); } /* TEST */ $str = 'Google, google, bing, Bing, AltaVista, altavista, AlTaViStA'; echo 'STRING: '.$str.'<br />'; echo 'Replaced: '.replaceWords($str); /* TEST OUTPUT STRING: Google, google, bing, Bing, AltaVista, altavista, AlTaViStA Replaced: Yahoo, Yahoo, Duck Duck Go, Duck Duck Go, AWWWWW YEAAAAAAH, AWWWWW YEAAAAAAH, AWWWWW YEAAAAAAH */ On an extra note if you really wanted to do you it your way, make sure after the first you use the correct variables, otherwise it's not going to do all of them (well it will but won't produce the desired result). Edited April 10, 2012 by Djkanna Quote
Djkanna Posted April 10, 2012 Posted April 10, 2012 Anywhere you want to use it. Bare in mind, I have no idea of GRPG's structure, set up or generally anything about the engine. So just use it where you need it. Quote
thebobby Posted April 10, 2012 Author Posted April 10, 2012 ok wat if i do it my way wat varibles you talking about Quote
thebobby Posted April 10, 2012 Author Posted April 10, 2012 $msgtext = str_replace(".yahoo", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $msgtext = str_replace(".ebay", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $msgtext = str_replace(".coke", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $msgtext = str_replace(".green", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); Quote
thebobby Posted April 10, 2012 Author Posted April 10, 2012 if ($_POST['newmessage'] != "") { $to = $_POST['to']; $from = $user_class->id; $timesent = time(); $subject = str_replace("yahoo", " ", htmlspecialchars($_POST['subject'], ENT_QUOTES )); $msgtext = str_replace(".yahoo", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $send_person = new User($to); $checkuser = mysql_query("SELECT `id` FROM `grpgusers` WHERE `id`='".$to."'"); $username_exist = mysql_num_rows($checkuser); this is wat i have Quote
Djkanna Posted April 10, 2012 Posted April 10, 2012 Then after the first, you would use $msgtext = str_replace('...', '', $msgtext); But this isn't really a usable way, imagine having 50+ words to replace. Or use an array within the str_replace(); str_ireplace( array ('Google', 'Yahoo'), array ('Duck Duck Go', 'AltaVista'), $var); Quote
thebobby Posted April 10, 2012 Author Posted April 10, 2012 $msgtext = str_replace( array ('Google', 'Yahoo'), array ('Duck Duck Go', 'AltaVista'), $var); wont let any words through Quote
thebobby Posted April 10, 2012 Author Posted April 10, 2012 how would i add bbcodes to mail as i can add str_replace to that Quote
HauntedDawg Posted April 10, 2012 Posted April 10, 2012 php.net/str_ireplace $msgtext = str_replace(".yahoo", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $msgtext = str_replace(".ebay", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $msgtext = str_replace(".coke", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); $msgtext = str_replace(".green", "google ", htmlspecialchars($_POST['msgtext'], ENT_QUOTES )); Clearly you have no idea of how php work's. So we will just spoon feed you :D Use $msgtext = str_replace(".yahoo", "google ", htmlspecialchars($msgtext, ENT_QUOTES )); $msgtext = str_replace(".ebay", "google ", htmlspecialchars($msgtext, ENT_QUOTES )); $msgtext = str_replace(".coke", "google ", htmlspecialchars($msgtext, ENT_QUOTES )); $msgtext = str_replace(".green", "google ", htmlspecialchars($msgtext, ENT_QUOTES )); Quote
rulerofzu Posted April 10, 2012 Posted April 10, 2012 Hahaha you are indeed on a roll today SRB Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.