简体   繁体   English

如何用“?”替换每个字符用 php 在字符串中标记

[英]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与 php 我想将其更改为


??????

my query currently is this, i cant continute yet cus the?我目前的查询是这样的,我还不能继续吗? marks分数


namespace modules\xenforums\sql;

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?我这样做是因为我做了一个 php mysqli 查询生成器,现在我试图用? to get the amount of given parameter获取给定参数的数量

iv tried using str_replaces but that only does 1 specific iv 尝试使用 str_replaces 但这仅适用于 1 个特定的

i also had the idea of doing str_replace for every char, but that's too tedious我也有为每个字符做 str_replace 的想法,但这太乏味了

iv also thought about just doing it for the current data types, but for other data base systems thats not all the same iv 还考虑过只针对当前数据类型执行此操作,但对于其他数据库系统,情况并非完全相同

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.并创建一个新字符串,通过使用 for 循环将字符数量作为问号放入。

the result would be something like that:结果将是这样的:

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

for ($i =0 ; $i < strlen(input) ; $i++) {
    $output .= "?";
}

One line code for this:一行代码:

str_pad('', strlen($string), '?');

Or better yet:或者更好:

str_repeat('?', strlen($string));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM