Re: array_search function bugged?

From: Date: Wed, 22 Mar 2006 06:20:10 +0000
Subject: Re: array_search function bugged?
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-232393@lists.php.net to get a copy of this message
Richard Lynch wrote:
On Mon, March 20, 2006 8:35 pm, je killen wrote:
I really don't understand, though, why you are doing things the way you describe...
      
I only want one image file for each distinct letter, no repeats because I can't put two or more files with the same name in the same dir. The images need to be drug around DHTML style and reassembled into the correct word. Javascript needs to be able to establish when the chars are in the correct order so I need to have php feed it a formula to refer to.
    
Okay, now we are getting somewhere! The easiest way to meet the unique filename requirement is to name each file after its letter: a.png b.png c.png Of course, they only need to APPEAR that way to the browser and Javascript. In reality, you may not actually have a file named "a.png" at all. For example, if your HTML is like this: <img src="/drawchar.php/a.png" /> And you have a PHP script drawchar.php like this: <?php //EG: $path_info will be "/a.png", //because that is what is in tha URL AFTER the PHP script name $path_info = $_SERVER['PATH_INFO']; //get JUST the one letter $char = substr($path_info, 1, 1); //Create the image: $image = imagecreatetruecolor(40, 10); //Boring colors, but works for now: $white = imagecolorallocate($image, 255, 255, 255); $black = imagecolorallocate($image, 0, 0, 0); //make the background white: imagefilledrectangle($image, 0, 0, 39, 9, $white); //draw the character: $font = 3; //Fonts can be 1 through 5 $x = 2; $y = 38; imagechar($image, $font, $x, $y, $char, $black); //Find out how big the image is: ob_start(); At this point, could you have an switch statement that checked the extension that you sent in the url and make it run the corresponding imagepng(), imagejpg(), and imagegif() ?
imagepng($image); $image_raw = ob_get_contents(); ob_end_clean(); $image_length = strlen($image_raw); //Send suitable headers: and then here send the corresponding header too.
Just a thought about making it even more universal. jl
header("Content-type: image/png"); header("Content-length: $image_length"); //Send the data: echo $image_raw; ?> You can now just pass the word 'dissatisfaction' around, and use PHP or JavaScript to output individual images. I'll do it in PHP: <?php $word = 'dissatisfaction'; for ($i = 0, $len = strlen($word); $i < $len; $i++){
    $char = $word[$i]; //or use substr if you like
    echo "<img src=\"/drawchar.php/$char.png\" />";
} ?> I haven't run this code to test it, so there might be a typo, but it's going to be MUCH easier to maintain than what you've got going...


« previous php.general (#232393) next »