Advertisement

01.26.2007 at 05:30PM PST, ID: 22138812
[x]
Attachment Details

Removing the space from $data = explode("\n", $_POST['var']);

Asked by cstormer in PHP and Databases, PHP Scripting Language

Tags: explode, space

I have this code:

$data = explode("\n", $_POST['multiplekeywords']);

When I take $data and insert it into a database like:

foreach ($data as $keyword) {
 if (trim($keyword) != '') {
      $sql = "INSERT INTO listing (campaign_name,adgroup_name,keyword_name,domain,max_bid,phrase,exact) VALUES ('$campaign','$adgroup','$keyword','$domain','$bid','$phrase','$exact')";
        
      $result = mysql_query($sql, $connect) or die(mysql_error());
        echo mysql_error();
        echo "New Listing Added To Database <br />";
        }
        }
   }

It seems to ad an extra space at the end of the keyword value, at least for all the values besides the last, if i have 10 values values in that array, the first nine will have an extra space attached.  How could I remove this space?Start Free Trial
 
Keywords: Removing the space from $data = ex…
 
Loading Advertisement...
 
[+][-]01.26.2007 at 06:50PM PST, ID: 18408781

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP and Databases, PHP Scripting Language
Tags: explode, space
Sign Up Now!
Solution Provided By: babuno5
Participating Experts: 2
Solution Grade: A
 
 
[+][-]01.27.2007 at 12:39AM PST, ID: 18409436

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32