/    Sign up×
Community /Pin to ProfileBookmark

Why Doesn’t This Work?

The following code encodes a string into a bar code. Everything works fine except, when 0’s are entered into the string. – Why is this?

Upon entering one or more 0’s into the string variable (e.g. “101010”), the bar code generated for some reason enlarges in width, rather than staying the same.

However, the code found at the following URL, works perfectly. How do I get my code to run like the code at the following URL, where the bar code width doesn’t change upon entering “111111”, “101010” or any other six digit value?

[B]URL: [/B][URL=”http://www.sid6581.net/cs/php-scripts/barcode/”]http://www.sid6581.net/cs/php-scripts/barcode/[/URL] – Click “Download the PHP script”.

Any Help Would Be Greatly Appreciated! – I am well and truly stuck! 😡

[CODE]<?php
$rectangle_width = 2;
$rectangle_height = 100;

$image = imagecreatetruecolor(300, 188);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);

imagefill($image, 0, 0, $white);
imagerectangle($image, 0, 0, 298, 186, $black);

$find = array(‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘*’);
$replace = array(‘1010001110111010’, ‘1110100010101110’, ‘1011100010101110’, ‘1110111000101010’, ‘1010001110101110’, ‘1110100011101010’, ‘1011100011101010’, ‘1010001011101110’, ‘1110100010111010’, ‘1011100010111010’, ‘1000101110111010’);

$string = ‘*111111*’;
$textstring = str_replace($find, $replace, $string);

$j = 11;
$sarray = str_split($textstring, 1);
for($i = 0; $i < count($sarray); $i++)
{
if($sarray[$i] == ‘0’)
{
imagefilledrectangle($image, $rectangle_width * $j, 150, ($rectangle_width * $j) + $rectangle_width, $rectangle_height, $white);
$j++;

}
elseif($sarray[$i] == ‘1’)
{
imagefilledrectangle($image, $rectangle_width * $j, 150, ($rectangle_width * $j) + $rectangle_width, $rectangle_height, $black);
$j++;
}
}

imagettftext($image, 10, 0, 120, 170, $black, “Verdana”, $string);

header(“Content-type: image/jpeg”);
imagejpeg($image);
imagedestroy($image);
?>[/CODE]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @Dysan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...