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 7719781
In Process

The Archive Base Latest Questions

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

I am trying to remove the slashes from magic quotes from an array. So

  • 0

I am trying to remove the slashes from magic quotes from an array. So I have two functions, one is to remove the slashes, another is to set the variable.

// Strip slashes from an array.
function strip_magic_quotes($array)
{
    if (get_magic_quotes_gpc())
    {
        function stripslashes_array($array)
        {
            return is_array($array) ? array_map('stripslashes_array', $array) : stripslashes($array);
        }
        return stripslashes_array($array);
    }
    return $array;
}

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);

    # Strip slashes from the array if get_magic_quotes_gpc is on.
    $array = strip_magic_quotes($array);

    # This will return true or false.
    if(in_array('boolean', $params)) return isset($array[$key]) ? true : false;

    # This will regard '0' as a string.
    # Return value or 0 as a string.
    elseif(in_array('0', $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;
}

$array = array(
    'name'=>'Hello',
    'type'=>'{"page":"page"}'
);


# set the required array.
$items_variable = array(
    'name',
    'type'
);

# loop the array.
foreach( $items_variable as $item_variable )
{
    # set the main variables.
    $$item_variable = set_variable($array,$item_variable);
}

print_r($type);

I get this error in my live server which I don’t understand it,

Fatal error: Cannot redeclare stripslashes_array() (previously
declared in json.php:16) in
json.php on line 16

line 16 refers to this line function stripslashes_array($array) which does not seem to have any mistake.

Any idea how to fix this?

  • 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-01T03:30:07+00:00Added an answer on June 1, 2026 at 3:30 am

    What happens is that everytime you call the function strip_magic_quotes PHP tries to declare the function stripslashes_array.

    Why do you think you want to nest that function? If you really want to do it this way (which you shouldn’t) you can change it to:

    if (get_magic_quotes_gpc() && !function_exists('stripslashes_array')) {
    

    Although this fixes the issue you simply shouldn’t do it in the first place, because:

    • it would be better to disable (if possible) magic* for the better of mankind.
    • declaring functions in functions (although possible) should really be avoided in almost all cases.

    Or you could simply just drop that inner function completely if you don’t need it somewhere else and just let the code run in the outer function.

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

Sidebar

Related Questions

I'm trying to remove an item from an array based on string; public function
Trying to remove single quotes from around numbers. I'm working with third paty data
I am trying to remove a specific user from sharepoint and have hit a
I have two lists of type SelectListItem. I am trying remove the items in
I am trying to remove items from a nested list in Python. I have
I'm trying to remove a color from a picture imported (JPG) in Flash CS4
I'm trying to remove all but the first child component from a Java Container.
I'm trying to remove a class attribute from an element and add the class
I am trying to remove the attribute xmlns=http://webdev2003.test.com from the following xml using xsl/xslt,
Im trying to remove a single node from a doubly threaded linked list. What

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.