Fix php Array to string converions

45 views Asked by At

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.

1

There are 1 answers

0
ha3an On

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));