rule69 Posted June 17, 2008 Share Posted June 17, 2008 Can some1 tell me what im doing wrong here.... i dunno why it doesnt wana work properly :/... ??? it should print this: artist: artist1 track: title1 cat: genre1 artist: artist2 track: title2 cat: genre2 artist: artist3 track: title3 cat: genre3 but instead its doing it own thing by printing this out: artist: a track: t cat: g artist: r track: i cat: e artist: t track: t cat: n <?php $url = ' http://somethng.com/dir/artist1_-_title1_-_genre1_.mp3\n http://somethng.com/dir/artist1_-_title2_-_genre2_.mp3\n http://somethng.com/dir/artist1_-_title3_-_genre3_.mp3\n '; $urly = explode("\n", $url); $forms = 3; for($i=1;$i<=$forms;$i++){ $link = $urly[$i]; $lins = explode("\n",$link); list($artist, $track, $cat) = explode('-', strrchr($link, '/')); echo "<br />artist: ".unchar($artist[$i])."<br /> track: ".unchar($track[$i])."<br /> cat: ".unchar($cat[$i])."<br />"; } ?> thanks in advance Link to comment https://forums.phpfreaks.com/topic/110602-solved-str_replace-not-working-properly/ Share on other sites More sharing options...
micah1701 Posted June 17, 2008 Share Posted June 17, 2008 what does the unchar() function do? Link to comment https://forums.phpfreaks.com/topic/110602-solved-str_replace-not-working-properly/#findComment-567430 Share on other sites More sharing options...
rule69 Posted June 17, 2008 Author Share Posted June 17, 2008 <?php function unchar($text) { //Unwanted chars $char = array("%26", "%28", "%2C", "%27", "%5B", "%5D", "%20", "/", "_"); //Wanted Chars $repl = array("&", ")", ",", "(", "[", "]", " ", "", " "); //Replace Unwanted with Wanted $text = str_replace($char, $repl, $text); return $text; } ?> a function i made for cleaning encoded chars.... Link to comment https://forums.phpfreaks.com/topic/110602-solved-str_replace-not-working-properly/#findComment-567432 Share on other sites More sharing options...
kenrbnsn Posted June 17, 2008 Share Posted June 17, 2008 These lines are the culprit: <?php echo "<br />artist: ".unchar($artist[$i])."<br /> track: ".unchar($track[$i])."<br /> cat: ".unchar($cat[$i])."<br />"; ?> You are telling PHP to just print one character from each string. Remove the "[$i]" <?php echo "<br />artist: ".unchar($artist)."<br /> track: ".unchar($track)."<br /> cat: ".unchar($cat)."<br />"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/110602-solved-str_replace-not-working-properly/#findComment-567437 Share on other sites More sharing options...
rule69 Posted June 17, 2008 Author Share Posted June 17, 2008 thanks ken... that fixed it Link to comment https://forums.phpfreaks.com/topic/110602-solved-str_replace-not-working-properly/#findComment-567442 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.