まきの先生にきいて解決した
いったん$fooを$replaceにしたので、そのあとの行は全部判定先が$replaceになるとのこと。
引っかからなかったら$fooのままでいるのかと思ってた。
これで通った。
test001.php
<?php
echo str_replace("java","PHP","Hello, java world");
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>PHPエラーコード変換</title>
<link rel="stylesheet" href="test1.css">
</head>
<body>
<h1>phpのエラーメッセージを入力してね</h1>
<form action="test002.php" method="get">
<p><input type="textarea" name="hoge" value=""></p>
<button type="submit">send</button>
</form>
</body>
</html>
test002.php
<?php
$msg = $_GET["hoge"];
//print_r($msg);
//指定した文字列が一致したら置き換える
$foo=htmlspecialchars($msg,ENT_QUOTES);
//最初の一つだけ$foo,あとは$replaceになる
$replace = str_replace('Parse error: syntax error,', '文字が抜けているかスペルが変みたいだね、', $foo);
$replace = str_replace('Undefined variable', 'ごめんよこの変数が見つからないや→', $replace);
$replace = str_replace('unexpected end of file', '行の末尾に何か足りない(か多い)のかもしれない。→', $replace);
$replace = str_replace('Fatal error: Uncaught Error: Call to undefined', '未定義のなにかを呼び出そうとしている! あやしいのはこれだ→', $replace);
$replace = str_replace('Call to undefined function', '定義していない関数を呼び出そうとしている!これだ→ ', $replace);
$replace = str_replace('Warning: Cannot modify header information – headers already sent', 'headerで移動前に何か記述されてるよ', $replace);
?>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>PHPエラーコード変換</title>
<link rel="stylesheet" href="test1.css">
</head>
<body>
<h1>エラーコードを変換しました!</h1>
<div class="proto">
<h2><?php echo ("原文"); ?></h2>
<p class="foo"><?php echo $msg; ?></p>
</div>
<div class="arrow"><p>↓</p></div>
<div class="trans">
<h2><?php echo ("変換後"); ?></h2>
<p class="foo"><?php echo $replace; ?></p>
</div>
</body>
</html>
test1.css
body{
width:90%;
margin: 0 auto;
}
input{
width:90%;
margin:auto 0;
height:3rem;
}
.proto p{
color:#777;
}
h1{
font-size:1.5rem;
}
.proto h2{
font-size:1rem;
background: #eff;
}
.trans h2{
font-size:1rem;
background: #fee;
}
.proto{
padding: 0;
}
.trans{
padding: 0;
}
.foo{
border:solid 1px #ccc;
border-radius: 3rem;
padding:1.5rem;
}
.arrow{
text-align:center;
font-size: 1.2rem;
color:#777;
font-weight:bold;
margin:0;
}