Shadow Hatake Posted July 7, 2006 Share Posted July 7, 2006 Okay I have a problem. I want to echo the results of a str_replace() but when I put echo infront of it it goes into a huge loop. Here's my code:[code]<?php$test = "a b";$letters = array('a', 'b');$replace = array('t455', '5gr4');str_replace($letters, $replace, $test);?>[/code]So how should I go about doing this? Link to comment https://forums.phpfreaks.com/topic/13957-str_replace/ Share on other sites More sharing options...
Daniel0 Posted July 7, 2006 Share Posted July 7, 2006 Just put echo or print in front of the str_replace function. That will echo the result. Link to comment https://forums.phpfreaks.com/topic/13957-str_replace/#findComment-54432 Share on other sites More sharing options...
hackerkts Posted July 7, 2006 Share Posted July 7, 2006 You could also put it on a function, so it will be easier to use.[code]<?phpfunction replacewords($text) {$letters = array('a', 'b');$replace = array('t455', '5gr4');$text = str_replace($letters, $replace, $text);return $text;}echo replacewords("a b");?>[/code] Link to comment https://forums.phpfreaks.com/topic/13957-str_replace/#findComment-54438 Share on other sites More sharing options...
Shadow Hatake Posted July 7, 2006 Author Share Posted July 7, 2006 Daniel0: If you read my post I tried that. It sent it into an infinite loops.hackerkts: I'll try that. Link to comment https://forums.phpfreaks.com/topic/13957-str_replace/#findComment-54444 Share on other sites More sharing options...
Daniel0 Posted July 7, 2006 Share Posted July 7, 2006 [quote author=Shadow Hatake link=topic=99792.msg393177#msg393177 date=1152289934]Daniel0: If you read my post I tried that. It sent it into an infinite loops.[/quote]Strange, worked perfectly for me. Link to comment https://forums.phpfreaks.com/topic/13957-str_replace/#findComment-54458 Share on other sites More sharing options...
Shadow Hatake Posted July 7, 2006 Author Share Posted July 7, 2006 Odd. Would it make a difference if I was using more letters?This is the whole code I'm using.[code]<?php$test = "a";$letters = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); $replace = array( 'b5fc', 'c8hd', 'd8re', 'ej9f', 'f8jg', 'g8ph', 'hd7i', 'iokj', 'ji8k', 'kh0l', 'lbhm', 'm87n', 'nuvo', 'ohvp', 'p7yq', 'qjhr', 'ribs', 'soit', 't9nu', 'ud6v', 'v89w', 'w9sx', 'x8sy', 'y9dz', 'z8ha', 'a9jb');echo str_replace($letters, $replace, $test);?>[/code]http://www.infected-designs.com/replace.php Link to comment https://forums.phpfreaks.com/topic/13957-str_replace/#findComment-54543 Share on other sites More sharing options...
redarrow Posted July 7, 2006 Share Posted July 7, 2006 <?//This is erigi replace with no array.$a="i dont wont this text";$b ="please print me!";$replace=eregi_replace($a,"",$b);echo $replace;?> <?//This is eregi with array$a=array("i dont wont this text");$b=array("please print me!");$replace=eregi_replace($a[0],"",$b[0]);echo $replace;?><?//This is str_replace with no array.$a="i dont wont this text";$b ="please print me!";$replace=str_replace($a,"",$b);echo $replace;?> <?//This is str_replace with array$a=array("i dont wont this text");$b=array("please print me!");$replace=str_replace($a[0],"",$b[0]);echo $replace;?> Link to comment https://forums.phpfreaks.com/topic/13957-str_replace/#findComment-54556 Share on other sites More sharing options...
redarrow Posted July 7, 2006 Share Posted July 7, 2006 <?php$letters = array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); $replace = array( 'b5fc', 'm8hd', 'd8re', 'ej9f', 'f8jg', 'g8ph', 'hd7i', 'iokj', 'ji8k', 'kh0l', 'lbhm', 'm87n', 'nuvo', 'ohvp', 'p7yq', 'qjhr', 'ribs', 'soit', 't9nu', 'ud6v', 'v89w', 'w9sx', 'x8sy', 'y9dz', 'z8ha', 'a9jb');echo str_replace($letters[2]," ", $replace[1]);hope this helps ok. Link to comment https://forums.phpfreaks.com/topic/13957-str_replace/#findComment-54560 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.