Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to keep user submitted quotes as quotes in a picture
    primarykey
    data
    text
    <p>Hopefully someone will be able to tell me how to keep user quotes when generating an image. What I mean is if a user submits words like:</p> <blockquote> <p>don't</p> </blockquote> <p>or</p> <blockquote> <p>John said "hello"</p> </blockquote> <p>how can I keep them in the generated image. Currently it turns to </p> <blockquote> <p>don\t </p> </blockquote> <p>Here is my code:</p> <pre><code>&lt;?php function formattextimg( $text, $width = 960, $color = array( 0, 0, 0 ),$bgcolor = array( 255, 255, 255 ), $font = 2 ) { $width = ( ( isset( $width ) &amp;&amp; is_numeric( $width ) ) ? ( ( $width &gt;= 100 ) ? (int)$width : 100 ) : 960 ); $text = str_replace( array( '&lt;b&gt;', '&lt;/b&gt;', '&lt;strong&gt;', '&lt;/strong&gt;' ), '|', $text ); $text_b = preg_split( '/\|/', $text, -1, PREG_SPLIT_OFFSET_CAPTURE ); foreach($text_b as $k =&gt; $tb){if($k%2!=0){$textbold[($tb[1]-1)]=$tb[0];}} $text = str_replace('|','',$text); for( $i = 0; $i &lt; strlen( $text ); $i++ ) { if( $string_c &gt;= ( $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 =&gt; $string ) { imagestring( $im, $font, 5, ( $pos * imagefontheight( $font ) ), $string, $color ); } $len = 0; foreach( $strings as $pos =&gt; $string ) { $len += ( strlen( $string ) + 1 ); if( count( $textbold ) &gt; 0 ) { foreach( $textbold as $cpos =&gt; $word ) { if( $cpos &lt;= $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; ?&gt; </code></pre> <p>If that is not possible can someone please tell me how to remove the:</p> <blockquote> <p>'</p> </blockquote> <p>and </p> <blockquote> <p>"</p> </blockquote> <p>I tried:</p> <pre><code>$text=$_REQUEST['text']; $text=str_replace('"', "", $text); $text=str_replace("'", "", $text); </code></pre> <p>But it did not work.</p> <p>thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload