Array Processing

2

I'm getting an array:

[{lat: "[{"area":"-22.88975203013098", lng: "-43.12695211119432,"},…]
0
:
{lat: "[{"area":"-22.88975203013098", lng: "-43.12695211119432,"}
1
:
{lat: "-22.88977179811704", lng: "-43.12685018725176,"}
2
:
{lat: "-22.88979650809557", lng: "-43.126624881694504,"}
3
:
{lat: "-22.890513095516", lng: "-43.12649077124376,"}
4
:
{lat: "-22.89054274732773", lng: "-43.126807271907516,"}
5
:
{lat: "-22.88975203013098", lng: "-43.12695211119432"}]"}

I need to remove this part:

"[{"area":"'

How do I do it?

    
asked by anonymous 03.10.2017 / 13:55

1 answer

3

One option is to use regex. Based on the excerpt you want to remove, you would use the preg_replace method to replace the desired value with an empty string . The default would be:

$pattern = '/\"\[{"area":"/s'; 

See working on ideone .

See regex running .

And as a bonus, see below with Javascript.

str = '[{lat: "[{"area":"-22.88975203013098", lng: "-43.12695211119432,"},…] 0 : {lat: "[{"area":"-22.88975203013098", lng: "-43.12695211119432,"} 1 : {lat: "-22.88977179811704", lng: "-43.12685018725176,"} 2 : {lat: "-22.88979650809557", lng: "-43.126624881694504,"} 3 : {lat: "-22.890513095516", lng: "-43.12649077124376,"} 4 : {lat: "-22.89054274732773", lng: "-43.126807271907516,"} 5 : {lat: "-22.88975203013098", lng: "-43.12695211119432"}]"}';

console.log(str.replace(/\"\[{"area":"/g,'')); 
    
03.10.2017 / 15:09