Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
PHPで文字列全体を星に置き換えるソリューションが必要です。たとえば、次のような文字列があります。
テスト test123 test1234
テスト
test123
test1234
文字列の長さに応じて、次のように文字列を星に置き換えます。
test長さは 4 文字なので、4 つ星に置き換えられ****ます。
test
****
test123は 7 文字なので、星 7 に置き換えられ*******ます。等々...
*******
そのための良い解決策はありますか?
$string = str_repeat('*', strlen($string));
すべての星で構成され、元の長さと同じ長さの新しい文字列を作成するだけです。