Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8577923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:16:10+00:00 2026-06-11T20:16:10+00:00

I have this string $s = ‘Yo be [diggin = array(fruit=> apple)] scriptzors!’; which

  • 0

I have this string

$s = 'Yo be [diggin = array("fruit"=> "apple")] scriptzors!';

which then gets checked by

$matches = null;
preg_match_all('/\[(.*?)\]/', $s, $matches);
var_dump($matches[1]);

but what I want it to do is the following, it should return the following

print "yo be";
$this->diggin(SEND ARRAY HERE);
print "scriptzors!";

EDIT to show issue with below answer

$s = 'Yo be [diggin = array("fruit"=>"apple")] scriptzors!';
$matches = null; 
preg_match_all('/\[(.*?)\]/', $s, $matches);

$var = explode(' = ', $matches[1]);
print $var[0]; //THIS DOES NOT PRINT
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:16:11+00:00Added an answer on June 11, 2026 at 8:16 pm

    You’re sort of close. You can explode the string with = but with spaces included around the =. Then the first element would be the function name, in this case diggin and the second element would be the array but as a string. You’ll need to eval that one so that it’ll be a proper array data type.

    $var = explode(' = ', $matches[1][0]);
    call_user_func_array(array($this, $var[0]), eval($var[1] . ';'));
    // or do 
    $this->{var[0]}(eval($val[1] . ';'));
    

    As an alternative, you can also modify the regex so that you don’t have to call explode.

    preg_match_all('/\[([a-z0-9_]*)\s*?=\s*(.*)\]/i', $s, $matches);
    

    Either way, you’ll want to make sure that you sanitize the user input because eval can be evil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this string: $array= 'orange, fruit, apple juice' I want to count the
I have this string, which is generated by dojo.toJson() function: {page:accommodation task=viewList,language:undefined} When decoding
I have this string $string = some words and then #1.7 1.7 1_7 and
I have this string hey {Bobby|Apple|Peter}, nice to meet you {David} and this regex:
I have this string: $delims = ',^.;:\t' (which is used in a preg_replace() call).
I have this string : 0=&task=rose&duration=1.25&user=15&1=&task=daisy&duration=0.75&user=25&2=&task=orchid&duration=1.15&user=7 I want this array structure : array( array(
I have this string (Java 1.5): :alpha;beta:gamma;delta I need to get an array: {:alpha,
I have this String which I used with Runtime.exec() in JVM in Windows XP.
I have this string 11110000 , which represents a byte . I want to
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.