Blitz Posted June 7, 2006 Report Share Posted June 7, 2006 Es ievacu no POST vertibu! Vertiba ir integer tipa (1,2,3,4,5,6..). Pec tam vinu izlaizu cauri: $string-POST['string'] $string=trim($string); $string=strip_tags($string); $string=addslashes($string); echo "$string"; ok, redzu ka vertiba ir 1. pec tam taisu parbaudi is_integer($string) un atkriez man false, kautgan vertiba ir integer tipa, var_dump atgriez ka vertiba ir char(1). Jautajums: Kapec php automatiksi nepieskir mainiga tipu, tb integer? Kas varetu but pa problemu? izmeginaju ari $string2=$string; bet taa pat $string2 paliek char(1)... Kas par problemam? Link to comment Share on other sites More sharing options...
KAC Posted June 7, 2006 Report Share Posted June 7, 2006 kaapeec tu liec strip_tags un veel viskautko veertiibai, kurai zinaams, ka jaabuut ir integeram. lieto labaak $x = (int)POST['x']; vai $x = floor(POST['x']); Link to comment Share on other sites More sharing options...
Blitz Posted June 7, 2006 Author Report Share Posted June 7, 2006 nee nu es jau input lauka visadus brinumus varu sarakstit! Tur jau taa lieta, ja es ierakstu "aa" tad vinu man pataisis pa integeru $x = (int)POST['x']; un izstures is_integer parabudi... Link to comment Share on other sites More sharing options...
[Ya] Posted June 7, 2006 Report Share Posted June 7, 2006 a tu uztaisi pārbaudi ar regexp :) preg_match("/\d+/",$string); Link to comment Share on other sites More sharing options...
v3rb0 Posted June 7, 2006 Report Share Posted June 7, 2006 vēl var šitā if(intval($string) == $string) {/* ir ok */} else {/* nav ok*/} un par preg_match tulīt no bubu dabūsi par lielgabaliem un zvirbuļiem! Link to comment Share on other sites More sharing options...
Blitz Posted June 7, 2006 Author Report Share Posted June 7, 2006 ooo sitas bus tiesi laikaa: if(intval($string) == $string) {/* ir ok */} else {/* nav ok*/} Paļdis... Link to comment Share on other sites More sharing options...
[Ya] Posted June 7, 2006 Report Share Posted June 7, 2006 vēl var šitāif(intval($string) == $string) {/* ir ok */} else {/* nav ok*/} un par preg_match tulīt no bubu dabūsi par lielgabaliem un zvirbuļiem! kautkas pret Preg_match ? ja nepatiik preg_match tad var str_match :) Link to comment Share on other sites More sharing options...
Grey_Wolf Posted June 7, 2006 Report Share Posted June 7, 2006 (edited) [Ya] --> shajaa gadijumaa izmantot regularas izteiksmes ir vienkaarshi galiigi garaam.... if straadaa stipri vien aatraak nekaa reg. izteiksmes... Edited June 7, 2006 by Grey_Wolf Link to comment Share on other sites More sharing options...
bubu Posted June 7, 2006 Report Share Posted June 7, 2006 Kā vienmēr RFTM: http://lv.php.net/ctype_digit http://lv.php.net/is_int S_integer($x) pārbauda vai $x tips ir integers, bet nevis vai tā vērtība var tikt pārvērsta uz integeru. Ja tu gribi pārbaudīt vai $x ir integers/floats, vai arī strings, kuru var pārvēst uz integeru/floats, tad tev jālieto is_numeric fja. A ja vajag pārbaudīt vai strings satur tikai ciparus, tad jālieto ctype_digit($x) fja. A tas, kurš pregus ieteica - ja tev vajag zvirbuļus nomedīt, tad arī talkā ņemsi lielgabalu? Link to comment Share on other sites More sharing options...
Recommended Posts