String to Array (from text area box)

Hi all,

I wanted to compare the string between 2 area text box a & b, like that

Text area a
65628018
60105091
60107780
60109523
60110250
60110259
60113899
60116739

text area b
60105072
60105091
60107780
60109523
60109625
60110250
60110259
60113899
60116739
60116759

if the string matched , it will appear at area text box c, else , it will appear at area text box d ; Actually i tried 2 function explode() & preg_split() , but those two function seem need to define the string/number first , for example $keywords = preg_split("/[\s,]+/", “6562801894 6562802024 6562805194 6562805351 6562806403 6562808570 6562809240 6562811224 6562812593 6562814191”); it works :

print_r ($keywords)
Array ( [0] => 6562801894 [1] => 6562802024 [2] => 6562805194 [3] => 6562805351 [4] => 6562806403 [5] => 6562808570 [6] => 6562809240 [7] => 6562811224 [8] => 6562812593 [9] => 6562814191 )

But when i use a variable like $a , for example
$keywords = preg_split("/[\s,]+/", “$a”);
print_r ($keywords);
the result will show
Array ( [0] => )

so my question is how can i change to array from string (with a variable $a) like that?
Array ( [0] => 6562801894 [1] => 6562802024 [2] => 6562805194 [3] => 6562805351 [4] => 6562806403 [5] => 6562808570 [6] => 6562809240 [7] => 6562811224 [8] => 6562812593 [9] => 6562814191 )

Then i will use the function array_intersect() to compare two area text box.
Thanks.

Brgds/Brandon Chau

[php]$keywords = explode("\n", $_POST[‘textarea1’]);
$keywords = array_filter($keywords); //remove blank lines
print_r($keywords);[/php]

:o wonderful :smiley:

Can you explain what is the mean of \n ==>$keywords = explode("\n", $_GET[‘a’]);

Because i see an example at a website ==>$pieces = explode(" ", $pizza); when will use " "?

Thank you

Brgds/Brandon Chau

\n is a newline character. When you have entries in your text area on different lines then they are separated by a \n not a space.

Oh , thanks.

May i ask one more question ;D

How can i display the variable $diff (not match string) at the same textarea box? ?

i used foreach() to get the array value and “IF” to compare two textarea box value , but the result will appear 3 separate text area box if 3 string different; so my question is how can all of the $diff contain in one text area box? the code as below.

Thanks.

[php]

foreach ($abox as $avalue)
{

foreach ($bbox as $bvalue)
{
}

 if ($avalue==$bvalue)
   
               {
	     $same=$avalue;
	     echo "<textarea >$same</textarea>";
               }
	
               else
	    {
		  $diff=$avalue;
                     echo "<textarea >$diff</textarea>";
	    }

}[/php]

Brgds/Brandon Chau

Sponsor our Newsletter | Privacy Policy | Terms of Service