Raised This Month: $ Target: $400
 0% 

A little PHP help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 08-28-2006 , 20:12   A little PHP help
Reply With Quote #1

I am working on my fathers website right now and I have run into a stupid yet probably easy PHP problem. I need to split up a line that has items seperated by commas and each item is inside quotes. The problem is, inside some of the quotes are more commas. This is how a line looks for instance:

"green", "blue", "yellow, red", "orange"

I want to be able to split it up into:

green
blue
yellow, red
orange

I have it setup like so:

list($green, $blue, $yellowred, $orange) = split('REGEXBLAH!', $line);

$line is a line of a file that holds the information. All help will be appreciated.
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 08-29-2006 , 00:20   Re: A little PHP help
Reply With Quote #2

PHP Code:
//Given that $MyString holds the line:
//"green", "blue", "yellow, red", "orange"
//You will get $Array_of_things with each one seperated. The space and quotes need to be set up like you said. With quote then comma then space then quote again.
$Array_of_things str_replace("\"","",explode("\", \""$MyString));

//Now you can use
print_r($Array_of_things);
//Or use a
foreach($Array_of_things as $Key => $String)
{
    echo 
"$Key => $String<br />";

Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 08-29-2006 , 11:40   Re: A little PHP help
Reply With Quote #3

Didn't exactly work the way I wanted it to but I think I can work with it for now. It only just took all the quotes out and made it all into one line. I still want to seperate things by quotes.
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
Reply



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 -4. The time now is 09:44.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode