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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:43:19+00:00 2026-05-27T12:43:19+00:00

I have an array of values that I would like to run through htmlspecialchars

  • 0

I have an array of values that I would like to run through htmlspecialchars but with an argument such as this:

$param = htmlspecialchars($param, ENT_QUOTES);

The problem is, I have an array of values that I want to run htmlspecialchars on:

$array = array_map('htmlspecialchars', $array);

and I would like to know if there is a way to pass ENT_QUOTES into the array_map callback?

I can always use my own function that uses htmlspecialchars, but it would be nice if there was a way to do this already.


After the answer below, here is my end result:

$array = array_map('htmlspecialchars', $array, array_fill(0, count($array), ENT_QUOTES));

Which simply fills an array with as many values as $array has and it’s filled with ENT_QUOTE.

  • 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-05-27T12:43:20+00:00Added an answer on May 27, 2026 at 12:43 pm

    This should work if you pass a second array as parameter to array_map that will contain as many ENT_QUOTES elements as your number of elements in $array:

    $quote_style = ENT_QUOTES;
    $array = array('"',"'","''''''''''''\"");
    $ent_quotes_array = array($quote_style, $quote_style, $quote_style);
    $array = array_map('htmlspecialchars', $array, $ent_quotes_array);
    print_r($array);
    

    Or, a little bit more elegant:

    $array = array('"',"'","''''''''''''\"");
    $ent_quotes_array = array_fill(0, sizeof($array), ENT_QUOTES);
    $array = array_map('htmlspecialchars', $array, $ent_quotes_array);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array filled with values (twitter ids) and I would like to
I have an array that looks like this (the full list is here ):
I have an array of values that is passed to my function from a
I have a set of values that I'm pushing into an array in the
I have an array that has keys and values. For eg: Array ( [name]
I have an array that contains the RGB colour values for each pixel in
Lets say I have an array numbers that contains the following values: int numbers
I have a fitness function that is scoring the values on an int array
I have an array of values which is almost, but not quite sorted, with
I have two resize functions that I would like to perform one after the

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.