Lodius2000 Posted November 15, 2008 Share Posted November 15, 2008 I am taking this thread (http://www.phpfreaks.com/forums/index.php/topic,225600.0.html) in a new direction so i started a new thread i am still in the theory part here I have a list of bad words and their replacements, I explode on | then explode on : Run the script i have here, the second foreach just prints out as 'Array' $wordlist = "crap:cr*p|dang:d*ng|shoot:sh**t"; $words = explode('|', $wordlist); foreach ($words as $word){ print "$word<br>\n"; } print "<br>exploded on :<br>\n"; $on_colons = explode(':', $words); foreach ($on_colons as $on_colon){ print "$on_colon<br>\n"; } I want it to print out as foreach ($on_colons as $on_colon){ print "$on_colon[array_key], $on_colon[array_value]"; } EDIT: so that each line would read 'crap, cr*p' and so on //end edit i am lost on how to do that Thanks Link to comment https://forums.phpfreaks.com/topic/132797-solved-help-with-explode/ Share on other sites More sharing options...
ratcateme Posted November 15, 2008 Share Posted November 15, 2008 Try: foreach ($words as $word){ $word = explode(":",$word); $new_words[($word[0])] = $word[1]; } foreach($new_words as $word => $replacement){ echo "$word = $replacement\r\n"; } Scott. Link to comment https://forums.phpfreaks.com/topic/132797-solved-help-with-explode/#findComment-690612 Share on other sites More sharing options...
Lodius2000 Posted November 15, 2008 Author Share Posted November 15, 2008 brilliant, thankyou scott Link to comment https://forums.phpfreaks.com/topic/132797-solved-help-with-explode/#findComment-690613 Share on other sites More sharing options...
Lodius2000 Posted November 15, 2008 Author Share Posted November 15, 2008 k now im really confunded <?php //print a text box function input_text($element_name, $values){ print '<input type="text" name="' . $element_name .'" value="'; print htmlentities($values[$element_name]) . '"/>'; } $wordlist = "crap:cr*p|dang:d*ng|shoot:sh**t"; $words = explode('|', $wordlist); foreach ($words as $word){ $word = explode(":",$word); $new_words[($word[0])] = $word[1]; } print '<form name="create" method="POST" action="'.htmlentities($_SERVER['PHP_SELF']). '">'; foreach($new_words as $word => $replacement){ input_text($word,$word); print "\n \n"; input_text($word,$replacement); print "\n<br />\n"; } ?> prints <form name="create" method="POST" action="/Users/imaging/Desktop/TacoHTMLEditTemp.php"><input type="text" name="crap" value="c"/> <input type="text" name="crap" value="c"/> <br /> <input type="text" name="dang" value="d"/> <input type="text" name="dang" value="d"/> <br /> <input type="text" name="shoot" value="s"/> <input type="text" name="shoot" value="s"/> <br /> why is each value only the first letter? Link to comment https://forums.phpfreaks.com/topic/132797-solved-help-with-explode/#findComment-690621 Share on other sites More sharing options...
ratcateme Posted November 15, 2008 Share Posted November 15, 2008 try :<?php function input_text($element_name, $values){ print '<input type="text" name="' . $element_name .'" value="'; print htmlentities($values) . '"/>'; } $wordlist = "crap:cr*p|dang:d*ng|shoot:sh**t"; $words = explode('|', $wordlist); foreach ($words as $word) { $word = explode(":", $word); $new_words[($word[0])] = $word[1]; } print '<form name="create" method="POST" action="' . htmlentities($_SERVER['PHP_SELF']) . '">'; foreach ($new_words as $word => $replacement) { input_text($word, $replacement); print "\n \n"; input_text($word, $replacement); print "\n<br />\n"; } ?> Scott. Link to comment https://forums.phpfreaks.com/topic/132797-solved-help-with-explode/#findComment-690623 Share on other sites More sharing options...
Lodius2000 Posted November 15, 2008 Author Share Posted November 15, 2008 that worked but why would taking element name out of $values do it, Ive used this function as i posted it a thousand times and never had a problem Link to comment https://forums.phpfreaks.com/topic/132797-solved-help-with-explode/#findComment-690624 Share on other sites More sharing options...
ratcateme Posted November 15, 2008 Share Posted November 15, 2008 foreach ($new_words as $word => $replacement) { input_text($word, $new_words); print "\n \n"; input_text($word, $new_words); print "\n<br />\n"; } should work with your function as it gives it the array. Scott. Link to comment https://forums.phpfreaks.com/topic/132797-solved-help-with-explode/#findComment-690649 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.