Ok, call me lazy (and some of you may) but I'm in a hurry to get what should be a simple script off the ground.
I need to process a long list of text items ---names specifically. What I want is to have a simple form with text box into which I paste a string of names from a single Excel column, and when I hit submit, it will return a page(s) with the modified names ready for me to paste back into my spread sheet. I want it general purpose (may change the conversion function from time to time), but one use would be to convert a column of last names into the metaphone equivalents. I am OK with building the simple form, and I assume I will use the POST method to send the names-string to a php loop reading each into an array to be converted then echoed back to my browser. What I'm not clear on is how to break down the _POST variable into an array. Can I do an explode on it using \n as a separator?
As usual, thanks for your help.
Need clue. How to process long list of names
Moderator: General Moderators
Code: Select all
$arrayOfNames = explode('\n', $namesString)There are 10 types of people in this world, those who understand binary and those who don't
oops, doesn't seem to work...
Shouldn't that just echo "Jim"? Each name in $Names is on a new line. But I get
"Jim Sam Tom" and an error echoing $namesarray[1]
I also tried $names= $_POST['names'];
...sent it a names list, each on a new line from an html form and got the same result.
Code: Select all
<?
$names =
"Jim
Sam
Tom";
$namesarray= explode('\n', $names);
echo $namesarray[0];
?>"Jim Sam Tom" and an error echoing $namesarray[1]
I also tried $names= $_POST['names'];
...sent it a names list, each on a new line from an html form and got the same result.
Use var_dump/print_r to view the arrays.
Try with double quotes.
Try with double quotes.
Code: Select all
$array = explode("\n",$names);
print '<pre>'; print_r ($array); print '</pre>';
// You can also use commas or anything you would like spaces maybe instead of Line breaks(\n)
Zoxive is right - my mistake.Zoxive wrote:Try with double quotes.Code: Select all
$array = explode("\n",$names);
There are 10 types of people in this world, those who understand binary and those who don't