我以前问过为什么\ 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