希望有人能够告诉我如何在生成图像时保留用户引用。我的意思是,如果用户提交如下字词:
别
或者
约翰说“你好”
如何将它们保留在生成的图像中。目前它变成
不
这是我的代码:
<?php
function formattextimg( $text, $width = 960, $color = array( 0, 0, 0 ),$bgcolor = array( 255, 255, 255 ), $font = 2 ) {
$width = ( ( isset( $width ) && is_numeric( $width ) ) ? ( ( $width >= 100 ) ? (int)$width : 100 ) : 960 );
$text = str_replace( array( '<b>', '</b>', '<strong>', '</strong>' ), '|', $text );
$text_b = preg_split( '/\|/', $text, -1, PREG_SPLIT_OFFSET_CAPTURE );
foreach($text_b as $k => $tb){if($k%2!=0){$textbold[($tb[1]-1)]=$tb[0];}}
$text = str_replace('|','',$text);
for( $i = 0; $i < strlen( $text ); $i++ ) {
if( $string_c >= ( $width - ( (int)(imagefontwidth( $font ) / 2 ) ) ) ) {
$space = strrpos( $string, ' ' );
$string_sub = substr( $string, 0, $space );
$i = $i - ( strlen( $string ) - $space ) + 1;
$strings[] = $string_sub;
$string = '';
$string_c = 0;
}
$string .= $text{$i};
$string_c += imagefontwidth( $font );
}
$strings[] = $string;
$im = imagecreatetruecolor( $width, ( imagefontheight( $font ) * ( count( $strings ) ) ) );
imagesavealpha( $im, true );
$trans = imagecolorallocate( $im, $bgcolor[0], $bgcolor[1], $bgcolor[2] );
imagefill( $im, 0, 0, $trans );
$color = imagecolorallocate( $im, $color[0], $color[1], $color[2] );
$black = imagecolorallocate( $im, 0, 0, 0 );
foreach( $strings as $pos => $string ) {
imagestring( $im, $font, 5, ( $pos * imagefontheight( $font ) ), $string, $color );
}
$len = 0;
foreach( $strings as $pos => $string ) {
$len += ( strlen( $string ) + 1 );
if( count( $textbold ) > 0 ) {
foreach( $textbold as $cpos => $word ) {
if( $cpos <= $len ) {
$wpos = strpos( $string, $word );
if( $wpos !== false ) {
imagestring( $im, $font,
( $wpos * imagefontwidth( $font ) )+1,
( ( $pos ) * imagefontheight( $font ) ),
$word, $color
);
unset( $textbold[$cpos] );
}
}
}
}
}
return $im;
}
header( 'Content-type: image/png' );
imagepng( formattextimg( $text,300,array( 255, 255, 255 ),array( 128, 128, 128 ),16 ) );
exit;
?>
如果那不可能,有人可以告诉我如何删除:
'
和
"
我试过:
$text=$_REQUEST['text'];
$text=str_replace('"', "", $text);
$text=str_replace("'", "", $text);
但它没有用。
谢谢