Bunkertor 7 Posted November 3, 2009 Report Share Posted November 3, 2009 Sveiki! Es te eksperimentēju ar Array. Ideja ir tāda, ka skripts saņem inputu četrzīmju numura veidā. Sadala pa cipariem (to momentu jau es esmu pieveicis) un tad nosauc tos ciparus vārdā. Piemēram, ja inputs ir 4582, tad outputs ir four five eight two. Iespējams, ka es mēģinu sarežģīt lietas, bet: $inputnum = "4582"; $num1 = substr($num,0,1); $num2 = substr($num,1,1); $num3 = substr($num,2,1); $num4 = substr($num,3,1); $matchbox = array(1=>'one', 2=>'two', 3=>'three', 4=>'four', 5=>'five', 6=>'six', 7=>'seven', 8=>'eight', 9=>'nine', 0=>'zero'); foreach ($matchbox as $num1=>$numerals) { preg_match ($num1, $matchbox); if (count($matchbox) > 0) { echo $numerals; } } Vai tas ir pareizais virziens, vai labāk domāt ko citu? Paldies! Quote Link to comment Share on other sites More sharing options...
briedis Posted November 3, 2009 Report Share Posted November 3, 2009 (edited) Nez, imo var vienkāršāk $input = "12345678354w634"; //"neierobežotā" garumā šis var būt $matchbox = array('zero','one','two','three','four','five','six','seven','eight','nine'); //pirmais masīva elements ir ar indeksu 0, tālāk 1,2,3... $arr = str_split($input); foreach($arr as $item){ echo $matchbox[$item]; } Edited November 3, 2009 by briedis Quote Link to comment Share on other sites More sharing options...
Bunkertor 7 Posted November 3, 2009 Author Report Share Posted November 3, 2009 wow. Neatceros, kurš, bet kāds gudrs vīrs teica, ka viss ģeniālais esot vienkāršs. Briedi, paldies, žetons! Quote Link to comment Share on other sites More sharing options...
Bunkertor 7 Posted November 10, 2009 Author Report Share Posted November 10, 2009 Atkal kaut kas nedarbojas. Mēģinu pielāgot šo skriptu, lai viņš zīmē cipariņus :) Sanāk tā, ka man viens foreach ir iekš otra... pareizāk sakot, nesanāk <?php $cardnum = "4586"; $matchbox = array('Zero','One','Two','Three','Four','Five','Six','Seven','Eight','Nine'); $xcoords = array(100, 120, 130, 140); foreach ($xcoords as $value) { $arr = str_split($cardnum); foreach($arr as $item { $output = $matchbox[$item]; ImageString($image, 4, $xcoords[$value], 100, $output, $blue); } } ?> Respektīvi, viņam vajadzētu zīmēt tos cipariņus ar 10 pikseļu atstatumu, bet viņš nezīmē. Varbūt kādam ir kāda laba ideja. Quote Link to comment Share on other sites More sharing options...
Val Posted November 10, 2009 Report Share Posted November 10, 2009 uz to pusi, pārbaudi pats. $image = imagecreate(300, 300); $bg = imagecolorallocate($image, 255, 255, 255); $textcolor = imagecolorallocate($image, 0, 0, 255); $input = "1478"; $matchbox = array('zero','one','two','three','four','five','six','seven','eight','nine'); $arr = str_split($input); $xcoords = array(10, 90, 170, 240); foreach($arr as $k=>$item) { $value = $matchbox[$item]; ImageString($image, 4, $xcoords[$k], 100, $value, $textcolor); }; header('Content-type: image/png'); imagepng($image); imagedestroy($image); Quote Link to comment Share on other sites More sharing options...
Bunkertor 7 Posted November 11, 2009 Author Report Share Posted November 11, 2009 superīgi, Val, tagad darbojas. Paldies. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.