homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Data Formatting Question

 11:02 pm on Jan 3, 2010 (gmt 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)

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)

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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved