Jump to content

[SOLVED] help with explode


Lodius2000

Recommended Posts

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

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?

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.

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.