Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
Explode string [ ]

Hellow.

i have a string output. "zoneAdd[1][home][group]"

I need.

$task = "ZoneAdd" $id = 1 $place = "home" $type = "group"

How to spit these guys? I need a PHP or javascript solution.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Here's one way with Javascript. You can split the string using regex. It can output an array and from there you can loop and assign the strings to the variables you need

const str = "zoneAdd[1][home][group]"
const strArr = str.replace(/[\[\]']+/g,' ').trim().split(' ')

const task = strArr[0] 
const id = strArr[1] 
const place = strArr[2] 
const type = strArr[3]
console.log({strArr, task, id,place,type})

about 4 years ago · Juan Pablo Isaza Report

0

Here is the PHP solution if you want to split without regex

<?php
     $string="zoneAdd[1][home][group]";
     $arr=explode("[", $string);
     foreach ($arr as $key=>$item) {
         $arr[$key]=explode("]", $item)[0];
     }
     $task=$arr[0];
     $id=$arr[1];
     $place=$arr[2];
     $type=$arr[3];
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!