3
0

More than 3 years have passed since last update.

php アルゴリズム備忘録

Last updated at Posted at 2020-06-23

文字列の切り出し

任意の文字列とその文字列の「何文字目」から「何文字」取得するかをプログラムする構文

hoge.php
<?php 
  $X = fgets(STDIN); 
  $Y = fgets(STDIN);
  echo substr($X, 0, $Y) . "\n";
?>

substr関数

文字を切り出す関数

substr(任意の文字列、 X文字目から、 Y文字切り取る) 

絶対値取得

abs関数

hoge.php
<?php 
  $num = fgets(STDIN);
  echo abs($num), PHP_EOL;

標準入力

hoge.php
$input=explode(' ',trim(fgets(STDIN)));
echo $input[0];
echo $input[1];
echo $input[2]; .............

自動的に配列に入れてくれる

大文字から小文字に変換

strtoupper関数

[string] [to] [upper]ね、、読みづら、、、、

hoge.php
<?php
  $str = trim(fgets(STDIN));
  echo strtoupper($str) . "\n";
?>
3
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
3
0