Jump to content

Foreach help please


spires

Recommended Posts

Hi Guys.

 

I'm trying to join two arrays together. I'm inputing one row of words into one textarea and another row of words into another textarea. Then trying to join the two lots of text tpgether.

 

Example:

textarea 1:

blackberry

black berry

 

textarea 2:

pearl

curve

 

Results:

blackberry pearl

blackberry curve

black berry pearl

black berry curve

 

Here the site so far:

http://www.spirestest.com/Adwords%20tools/extend-keywords.php

 

Here is my code so far:

<form name="form1" method="post" action="<?php echo $PHP_SELF; ?>">
<table width="1100" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><textarea name="keywords" cols="60" rows="8" class="body_text" id="keywords"><?PHP echo stripslashes($_POST['keywords']); ?></textarea></td>
    <td><textarea name="ext_keywords" cols="60" rows="8" class="body_text" id="ext_keywords"><?PHP echo stripslashes($_POST['ext_keywords']); ?></textarea></td>
  </tr>
  <tr>
    <td><input name="submit12" type="submit" value="submit" /></td>
    <td> </td>
  </tr>
</table>
</form>
<BR>
<?php 

		$keywords = stripslashes($_POST['keywords']);
		$keyword_array = explode("\n", $keywords);

		$ext_keywords = stripslashes($_POST['ext_keywords']);
		$ext_keyword_array = explode("\n", $ext_keywords);
		// $keyword = $keyword_array[1];

		foreach ($keyword_array as $keyword) {
    				$keyword = trim($keyword);
		}

		foreach ($ext_keyword_array as $ext_keywords) {
    				$ext_keywords = trim($ext_keywords);
		}

		$key = $keyword.' '.$ext_keywords;	



?>
<form name="form2" method="post" action="<?php echo $PHP_SELF; ?>">
<table width="1100" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><textarea name="key" cols="60" rows="8" class="body_text" id="keywords"><?PHP echo $key; ?></textarea></td>
    <td></td>
  </tr>
  <tr>
    <td><input name="submit12" type="submit" value="submit" /></td>
    <td> </td>
  </tr>
</table>
</form>

 

Thanks for your help

:)

Link to comment
Share on other sites

Hi

 

I just try it, but it didn't help.

 

		$keywords = stripslashes($_POST['keywords']);
		$keyword_array = explode("\n", $keywords);

		$ext_keywords = stripslashes($_POST['ext_keywords']);
		$ext_keyword_array = explode("\n", $ext_keywords);

		foreach ($keyword_array as $keywords) {
    			foreach ($ext_keyword_array as $ext_keywords) {
			$keywords = trim($keywords);
    				$ext_keywords = trim($ext_keywords);

			$key = $keywords.' '.$ext_keywords;	
		}
		}

 

Any other ideas please

 

Thanks for your help

Link to comment
Share on other sites

Looking at your code I see quite a few html errors and logic errors

 

Im not 100% how this should work but try

 

<?

$keywords = stripslashes($_POST['keywords']);

$keyword_array = explode("\n", $keywords);

 

$ext_keywords = stripslashes($_POST['ext_keywords']);

$ext_keyword_array = explode("\n", $ext_keywords);

// $keyword = $keyword_array[1];

 

foreach ($keyword_array as $keyword) {

    $keyword = trim($keyword);

}

 

foreach ($ext_keyword_array as $ext_keywords) {

    $ext_keywords = trim($ext_keywords);

}

 

                  foreach ($keyword_array as $keywords) {

    foreach ($ext_keyword_array as $ext_keywords) {

$keywords = trim($keywords);

    $ext_keywords = trim($ext_keywords);

 

$key .= $keywords.' '.$ext_keywords."\n";

}

}

 

 

 

 

 

?>    <form name="form1" method="post" action="<?php echo $PHP_SELF; ?>">

<table width="1100" border="0" cellspacing="0" cellpadding="0">

  <tr>

    <td><textarea name="keywords" cols="60" rows="8" class="body_text" id="keywords"><?PHP echo stripslashes($_POST['keywords']); ?></textarea></td>

    <td><textarea name="ext_keywords" cols="60" rows="8" class="body_text" id="ext_keywords"><?PHP echo stripslashes($_POST['ext_keywords']); ?></textarea></td>

  </tr>

  <tr>

    <td><input name="submit12" type="submit" value="submit" /></td>

    <td> </td>

  </tr>

</table>

 

<table width="1100" border="0" cellspacing="0" cellpadding="0">

  <tr>

    <td><textarea name="key" cols="60" rows="8" class="body_text" id="keywords"><?PHP echo $key; ?></textarea></td>

    <td></td>

  </tr>

  <tr>

    <td><input name="submit12" type="submit" value="submit" /></td>

    <td> </td>

  </tr>

</table>

</form>

<BR>

 

 

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.