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

  • Home
  • SEARCH
  • 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 7777277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:05:56+00:00 2026-06-01T18:05:56+00:00

How can I make a string act as a code? For instance, I want

  • 0

How can I make a string act as a code?

For instance, I want this string to be parsed as an array,

$config = '
    "allowable_tags" => "<p>",
    "span_regex" => null, 
    "allow_nbsp" => true, 
    "allow_class" => false
';

so,

function tidy($config = null){

    $default = array(
        "allowable_tags" => null,
        "span_regex" => null, 
        "allow_nbsp" => true, 
        "allow_class" => false
    );

    $config = array($config);

    # Loop the array.
    foreach($default as $key => $value)
    {
        # Set the variable.
        $$key = set_variable($config,$key)? set_variable($config,$key):$value;
    }

    return $allowable_tags;
}


var_dump(tidy($config));

Then I will get this as the result,

<p>

Is it feasible?

the dependant function,

function set_variable($array = array(),$key,$params = array())
{
    # If $params is not an array, let's make it array with one value of former $params.
    if(!is_array($params)) $params = array($params);
    if(!is_array($array)) parse_str($array, $array);

    # When you want a variable to return a boolean, this will return true or false.
    if(in_array('boolean', $params)) return isset($array[$key]) && $array[$key] === true ? true : false;

    # This will regard '0' as a string.
    # Return value or 0 as a string.
    elseif(in_array('zero_to_string', $params)) return isset($array[$key]) && ($array[$key] == '0') ? trim($array[$key]) : null;

    # Return null as string if 'null_to_string' is set.
    elseif(in_array('null_to_string', $params)) return isset($array[$key]) && !empty($array[$key]) ? trim($array[$key]) : 'null';

    # Check if the key is an array.
    elseif(isset($array[$key]) && !empty($array[$key]) && is_array($array[$key])) return isset($array[$key]) && !empty($array[$key]) ? $array[$key] : null;

    # This will regard '0', empty space as falsey.
    # Return value or null.
    else return isset($array[$key]) && !empty($array[$key]) ? trim($array[$key]) : null;
}
  • 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-01T18:05:58+00:00Added an answer on June 1, 2026 at 6:05 pm

    instead of making a custom function to parse the string representation of config vars to an array, why not just use an existing format such as JSON? then you can simply call json_decode() and get an array back. Also if this is for user submitted/entered config values, JSON is widely known, easy to learn and somewhat safe because no code is executed.

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

Sidebar

Related Questions

I need to know how i can make a string like hello to Hello
std::map<std::string, int> m; // Can I make assumption that m[NoSuchKey] will return 0? std::cout
How can I make my strings and text attributes bold in my actionscript code?
I can make batch or vbs file on windows and run. this can automate
Does the Yii framework contain a function that can make a string usable in
I know marking string parameters as const can make a huge performance difference, but
Is there any advantage of making String as final or can we make String
So i can make drawtext break a string if the string has spaces, or
The code below does not return any errors and I can make it return
How can I make the genOut/String fire? module IOStream where import System.IO import System.IO.Unsafe

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.