0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

回文判定のプログラム(PHP)

Last updated at Posted at 2023-08-11

「何に使うんだ?」と思いつつも、備忘録として書いておく。

$line = trim(fgets(STDIN));
for($i=strlen($line);$i>=0;$i--){
    $kotae.=mb_substr($line,$i,1);
}
if($kotae==$line){
    echo "YES";
}else{
    echo "NO";
}

コンソールから拾うため、trim(fgets(STDIN)としてある。
$line:判定する文。
$kotae:$lineをひっくり返した文。

※mb_substrだと日本語でも利用できる。
substrだと英文のみ対応。

半角$が表示されない( ノД`)シクシク…。。

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?