Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-19-2012, 07:53 PM   PM User | #1
frank5050
New Coder

 
Join Date: Feb 2011
Posts: 32
Thanks: 3
Thanked 0 Times in 0 Posts
frank5050 is an unknown quantity at this point
Split Apart Data Being Received - Newbie Help

I'm currently receiving some data into a single database field as shown below:

SomeVariable1 is string of text and it can have commas hence it's being separated by tilde ~ SomeVariable2, SomeVariable3, SomeVariable4


The data I'm receiving is a combination of various variables dumped into a single databse field. The first variable is separated by a ~ (tilde) because the first variable has customer comments and can include commas also. The rest of the variables are separated by commmas.

What I need to do is split apart the string so I can display them on a web page separately in different columns.

What I really want to do is along the lines:


$variable1 = All text before tilde

$variable2 = SomeVariable2

$variable3 = SomeVariable 3

$variable4 = SomeVariable 4

How can I accomplish this?

I'm a newbie in PHP and I'd appreciate any help.
frank5050 is offline   Reply With Quote
Old 10-19-2012, 09:22 PM   PM User | #2
Redcoder
Regular Coder

 
Redcoder's Avatar
 
Join Date: May 2012
Location: /dev/couch
Posts: 309
Thanks: 2
Thanked 46 Times in 45 Posts
Redcoder has a little shameless behaviour in the past
Use the explode() function:

PHP Code:

//Explode() separates the string into a numerically indexed array starting from 0
<?php

$separate1 
explode('~'$variable1);
$variable2 $separate1[0]; //The variable before the ~
  //$separate1[1] has the second part of the original variable after removing 
//the part before the ~
//You can specify your own variables using list()
//e.g list($str1, $str) = explode('~', $variable1);
$separate2 explode(','$separate[1]);
$variable2 $separate2[0]; //The variable before the first comma
$variable3 $separate2[1]; //The 3rd variable

?>
__________________
For professional Hosting and Web design.....


NetEssentials.co.uk
Redcoder is offline   Reply With Quote
Reply

Bookmarks

Tags
php, variable

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:32 PM.


Advertisement
Log in to turn off these ads.