以前、文字列の \n が改行を返さない理由を尋ねました。
これは、文字列を二重引用符で囲む必要があったためです。(ありがとう @Juhana !)
今は GET を使用しているので、URL のテキスト文字列を変更できます
$text = $_GET["msg"];
そしてURL:
http://www.mywebsite.co.uk/image.php?msg=Something\nElse
出力されるテキストは "Something\\nElse"
ですが、私が欲しいのは次のような改行です:
"Something
Else"
テキストにまだ 2 つのバックスラッシュがあるのはなぜですか?
「msg」が二重引用符で囲まれているため、改行を作成する必要があると考えるのは間違っていますか?
ありがとう
完全な PHP コードを編集
<?php
// Set the content-type
header('Content-Type: 画像/png');
// Create the image
$im = imagecreatetruecolor(400, 100); //image big enough to display two lines
// Create some colors
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
//$text = 'Testing\ntesting'; using SINGLE quotes like this results \\n
//$text = "Testing\ntesting"; using DOUBLE quotes like this results in line break
$text = $_GET["msg"];
// Replace path by your own font path
$font = 'arial.ttf';
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>