我以前問過爲什麼\ n在一個字符串中沒有返回換行符。imagettftext \ n換行符第2部分
這是因爲字符串需要在雙引號中。 (!感謝@Juhana)
現在我使用GET這樣我就可以在URL
$text = $_GET["msg"];
和URL更改文本字符串:
http://www.mywebsite.co.uk/image.php?msg=Something\nElse
結果在輸出文本「的東西\ \ nElse」
但我要的是一個換行符是這樣的:
‘一些
否則’
爲什麼文本仍然有這兩個反斜槓?
我認爲這是錯誤的,因爲「味精」在雙引號應該創建一個換行符?
感謝
EDIT完整的PHP代碼
<?php
// Set the 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);
?>
你試過用'
'而不是'\ n'??? – Ace 2012-03-29 13:32:01
是的,它只是顯示
就好像這就是我想讓圖片中的文字說的那樣。 – mattneedshelp 2012-03-29 13:35:25
請發佈完整的PHP代碼 – Ace 2012-03-29 13:38:33