Skip to content
Advertisement

how can i replace every single character with a “?” mark in a string with php

so for example i gave this string

sbbibs

with php i would like to change it to

??????

my query currently is this, i cant continute yet cus the ? marks

namespace modulesxenforumssql;

trait create_row {
    
    function create_row($types, $table, $column, $param, $conn) {
        
        $param = "'" . implode ( "', '", $param ) . "'";

        $placeholders = str_split($types);

        $a = str_replace(); // this is where i want to make every type to ?

        // posible value of $type, sssissb
        
        $query = "INSERT INTO {$table} ({$column}) VALUES ({$placeholders})";

        var_dump($a);
        
    }
    
}

how could i do so?

im doing this because i made a php mysqli query builder and now i’m trying to replace the data types with ? to get the amount of given parameter

iv tried using str_replaces but that only does 1 specific

i also had the idea of doing str_replace for every char, but that’s too tedious

iv also thought about just doing it for the current data types, but for other data base systems thats not all the same

Advertisement

Answer

When you want to make a string unreadable by replacing every character with a question mark you can just:

  • Get the length of your current string
  • And create a new string which puts the amount of characters in as a question mark by using a for loop.

the result would be something like that:

$input = "Test";
$output = "";

for ($i =0 ; $i < strlen(input) ; $i++) {
    $output .= "?";
}
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement