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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:13:32+00:00 2026-05-31T14:13:32+00:00

I will accept an alternative to sprintf only if you explain why it’s not

  • 0

I will accept an alternative to sprintf only if you explain why it’s not possible / highly not recommended

(code below)

i want to be inserting dynamicaly data from my arrays to a mysql DB. i’m also trying to experiment with sprintf, wich i recently heard about and want to start using it.

how can i take data from the 2nd foreach and store it inside the query via sprintf?

arrays :

############################################################
                        $csv->titles
############################################################
Array
(
    [0] => rating
    [1] => title
    [2] => author
    [3] => type
    [4] => asin
    [5] => tags
    [6] => review
)

############################################################
                        $csv->data
############################################################
Array
(
    [0] => Array
        (
            [rating] => 0
            [title] => The Killing Kind
            [author] => John Connolly
            [type] => Book
            [asin] => 0340771224
            [tags] => 
            [review] => i still haven't had time to read this one...
        )

    [1] => Array
        (
            [rating] => 0
            [title] => The Third Secret
            [author] => Steve Berry
            [type] => Book
            [asin] => 0340899263
            [tags] => 
            [review] => need to find time to read this book
        )
...

Code i’m working on :

$query  = "CREATE TABLE IF NOT EXISTS XXX (";
$query .= "ID int(11) NULL AUTO_INCREMENT,";
$query2 =   "SELECT * FROM XXX WHERE";

foreach($titlesArray as $keyTitles => $valuesTitles){
    $query  .= cleanForShortURL($valuesTitles)." varchar(255),";
    $query2 .= cleanForShortURL($valuesTitles)." = '%s' AND ";
}
$query2 =   substr($query2,0 ,-5);
$query .= "  PRIMARY KEY (`ID`)
            ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0 "; 
$mysqli->query($query);


foreach($dataArray as $key => $values){
    ################## PROBLEM HERE ####################
}

one of my attempt :

 foreach($dataArray as $key => $values){
        sprintf($query, eval(implode(",",$values)));
    }

in case someone ask (from php.net) :

    function cleanForShortURL($toClean) {
        $normalizeChars = array(
            'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', 
            'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', 
            'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', 
            'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', 
            'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', 
            'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', 
            'ú'=>'u', 'û'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f'
        );

        $toClean     =     str_replace('&', '-and-', $toClean);
        $toClean     =    trim(preg_replace('/[^\w\d_ -]/si', '', $toClean));//remove all illegal chars
        $toClean     =     str_replace(' ', '_', $toClean);
        $toClean     =     str_replace('--', '-', $toClean);

        return strtr($toClean, $normalizeChars);
    }
  • 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-31T14:13:35+00:00Added an answer on May 31, 2026 at 2:13 pm

    Avoid eval whenever possible. Try vsprintf:

    foreach($dataArray as $key => $values){
        vsprintf($query, $values);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to code a server in java which will accept the information from
In a translation-testing app (in Python) I want a regular expression that will accept
We're developing a service that will accept a POST request. Some of the POST
I am looking for a command that will accept (as input) multiple lines of
I have an application that will accept URLs from the built in web browser
I know there is a function somewhere that will accept a client rect and
Are there any libraries out there for Java that will accept two strings, and
I am trying to build an Oracle stored procedure which will accept a table
I'm trying to limit the number of connections my server will accept using semaphores,
I have a method, which will accept a parameter of a JQuery Object and

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.