1

I know its a strange question, but I have one input field that does a live search for locations. The final value is displayed like this:

State,Suburb,Post Code

NSW,Sydney,2210

What I need to do now is split the three values into single values and update them into my separate fields for one row.

I don't want to update multiple rows but just one.

e.g.:

fields ( state | suburb | postcode ) values ( NSW | sydney | 2210 )

What php commands would I use to split those commas off and create single $values for each item?

1
  • you can't split three values into single value. but you may split single value into three values. please consider rewriting your question. Commented Jan 18, 2012 at 1:58

5 Answers 5

2

Use explode on the string.

$values = 'A,B,C,D';
$values = explode(',', $values);

Each item can then be accessed from an array indexed from 0.

Sign up to request clarification or add additional context in comments.

Comments

1
$val = "NSW,Sydney,2210";
$valArr = explode(",", $val);
$query = "UPDATE MyTbl SET State = '$valArr[0]', Suburb = '$valArr[1]', Post_Code = '$valArr[2]' WHERE ...";

Comments

0

The easiest way I think, see the manual for explode:

$result_array = explode(',', $your_variable);

Comments

0

list($state, $suburb, $postcode) = explode(',', $value);

Comments

0

Would this work?

$header = "State,Suburb,Post Code"
$items = explode(",", $input)
$output = implode("|", $items)

so the output would become State|Suburb|Post Code

to access each value separately, you can use $items[0], $items[1] ..

$data = "NSW,Sydney,2210"
$items = explode(",", $input)
$output = implode("|", $items)

so the output would become NSW|Sydney|2210

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.