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
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?

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.