LoginSignup
1
0

More than 1 year has passed since last update.

【PHP基礎復習5】文字列から数値のみを抽出する

Posted at

[問題]
入力された文字列から数値の部分だけ取り出して出力しなさい。

コード

 $input = fgets(STDIN);
 echo preg_replace('/[^0-9]/', '', $input_line), PHP_EOL;

↓ 15kgと入力

結果

15

☆文字列から数値のみを抽出する
preg_replace(正規表現, 置換後の文字列, 対象の文字列);

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0