Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Data Formatting Question

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

Junior Member

10+ Year Member

joined:Mar 30, 2003
votes: 0

Hi All

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

An example of a line of data would be:


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?



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

Senior Member

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

joined:Nov 28, 2004
votes: 0

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)

Junior Member

10+ Year Member

joined:Jan 26, 2004
votes: 0

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);

Hope that helps!

M. Cold


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members