Welcome to WebmasterWorld Guest from 54.198.69.193

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Data Formatting Question

     
11:02 pm on Jan 3, 2010 (gmt 0)

10+ Year Member



Hi All

I am trying to parse through some data and I am having problems.

An example of a line of data would be:

.Wyoming,"544,270","532,981","523,414","512,841","506,242","502,988","499,189","497,069","492,982","493,958","493,783","493,782"

The problem here obviously is the quotation marks, as they are creating an error in PHP. Is there any way to remove these so that I can chop up this data? The data file is just too big to manually take out the quotation marks.

Any ideas?

Thanks!

Dave

12:18 am on Jan 4, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Ya got an image map there, doncha? :-)

The problem with taking out the quotes is that those are paired for a reason. If it's not an image map, you can bet the reasons are similar, the quoted values need to be associated, right?

I don't see why you can't pull the substring of the first element out (Wyoming,) now you have a string with "..data1..","..data2..", split up the pairs only, including the quotes, then split those pairs so the end result is a multidimensional array, like

$states = Array (
'Wyoming' =>
Array [0] => Array (544,270),
Array [1] => Array (544,270),
Array [2] => Array (532,981),
..... etc.

Otherwise, just str_replace/preg_replace the quotes, explode, shift the first item off the array, then do some math to keep the pairs associated. One way to do that would be to shift twice for each pair until the array is expended.

1:46 pm on Jan 4, 2010 (gmt 0)

10+ Year Member



What about something like this:

$str = '.Wyoming,"544,270","532,981","523,414","512,841","506,242","502,988","499,189","497,069","492,982","493,958","493,783","493,782"';

$aNodes = explode(',"', $str);
$aNodes = str_replace( '"', '', $aNodes);
print_r($aNodes);

Hope that helps!

M. Cold

 

Featured Threads

Hot Threads This Week

Hot Threads This Month