0

I have in my database record products and price on the same column. EG:

product name 2- RM 120.00

product name 6 - RM 10.00

product name 77 - RM 1.00

product name 3243 - RM 18.00

I am currently trying to separate the name & price into 2 columns, so the name column will only have 'product name' while price column only the price '120.00'

I tried using substr function but that would only work on the number number of characters behind. Is there anyway I can get all the numbers behind the '- RM' ?

2
  • 1
    You tried using substr - can you show us what you tried? Commented Nov 3, 2014 at 5:53
  • you can also use preg_match for your purpose, but frankly saying explode is a better option. Commented Nov 3, 2014 at 6:06

2 Answers 2

2
$data = explode(" - RM ", $record); //your (string) database record in $record

echo $data[0]; //product name 2
echo $data[1]; //120.00

echo $data[2]; //product name 6
echo $data[3]; //10.00
Sign up to request clarification or add additional context in comments.

Comments

0

The explode function makes this pretty easy.

$values = explode(' - RM ', $field);
var_dump($values);

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.