简体   繁体   中英

Fix php Array to string converions

I am using a 2008 PHP program to take an image, annotate it and create a thumbnail of the image.

The program works but throws a notice of an Array to String conversion.

The relevant code is:

$ttfont = 'Arial.TTF';
if ($ttfont != '') {
    # using ttf fonts
    $alpha   = range("a", "z");
    $alpha_u = range("A", "Z");
    $alpha = $alpha.$alpha_u.range(0, 9);
    //print_r($alpha);
    $_b = imageTTFBbox($fontsize,0,$ttfont,$alpha);
    //print_r($_b);
    $fontheight = abs($_b[7]-$_b[1]);
} else {

The error is in the line:

$alpha = $alpha.$alpha_u.range(0, 9);

The print_r 's are my debugging attempts.

you can use implode function like

implode("",range("a","z"))

for more information see https://www.php.net/manual/en/function.implode.php

   $alpha   = implode("",range("a","z"));
   $alpha_u = implode("",range("A","Z"));
   $alpha = $alpha.$alpha_u.implode("",range(0, 9));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM