AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Off-Topic (https://forums.alliedmods.net/forumdisplay.php?f=15)
-   -   A little PHP help (https://forums.alliedmods.net/showthread.php?t=44011)

knekter 08-28-2006 20:12

A little PHP help
 
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.

Xanimos 08-29-2006 00:20

Re: A little PHP help
 
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 />";



knekter 08-29-2006 11:40

Re: A little PHP help
 
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.


All times are GMT -4. The time now is 09:44.

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