PHP - Octet To Decimal
I'm making a connection to Active Directory using ADODB connection. I can read almost everything from this but some outputs are in an Octet format.
For example objectSID is giving me only a ?. Is there somebody that knows how to read or convert this? I've found a converter function in ASP maybe someone can translate this to PHP? Code: [Select] TXT_ObjectGUID = HexStrToDecStr(OctetToHexStr(objRecordSet.fields("objectSID"))) Function OctetToHexStr(arrbytOctet) ' Function to convert OctetString (byte array) to Hex string. Dim k OctetToHexStr = "" For k = 1 To Lenb(arrbytOctet) OctetToHexStr = OctetToHexStr _ & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2) Next End Function Function HexStrToDecStr(strSid) ' Function to convert hex Sid to decimal (SDDL) Sid. Dim arrbytSid, lngTemp, j ReDim arrbytSid(Len(strSid)/2 - 1) For j = 0 To UBound(arrbytSid) arrbytSid(j) = CInt("&H" & Mid(strSid, 2*j + 1, 2)) Next HexStrToDecStr = "S-" & arrbytSid(0) & "-" _ & arrbytSid(1) & "-" & arrbytSid(8) lngTemp = arrbytSid(15) lngTemp = lngTemp * 256 + arrbytSid(14) lngTemp = lngTemp * 256 + arrbytSid(13) lngTemp = lngTemp * 256 + arrbytSid(12) HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) lngTemp = arrbytSid(19) lngTemp = lngTemp * 256 + arrbytSid(18) lngTemp = lngTemp * 256 + arrbytSid(17) lngTemp = lngTemp * 256 + arrbytSid(16) HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) lngTemp = arrbytSid(23) lngTemp = lngTemp * 256 + arrbytSid(22) lngTemp = lngTemp * 256 + arrbytSid(21) lngTemp = lngTemp * 256 + arrbytSid(20) HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) lngTemp = arrbytSid(25) lngTemp = lngTemp * 256 + arrbytSid(24) HexStrToDecStr = HexStrToDecStr & "-" & CStr(lngTemp) End Function Similar TutorialsHi there, I have a database with table column called EXPAMOUNT
if EXPAMOUNT value was £5.50 My code at moment echo “Total Expenses   £” . $row[‘SUM(EXPAMOUNT)’]. “ Hi, I'm trying to force 2 decimal places with the following function but it 's not working. Any suggestions? Code: [Select] function ShippingCost() { $shippingCost = 4.00; number_format($shippingCost,2); return $shippingCost; } Hi I need to convert hex or Decimal to Binary but can't find any function. Any one have one or ideas please. Hi.. I encountered problem in rounding of numbers into two decimal places. here is my sample code: if($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 7917 AND $TotEarn <= 12500) { $TAX = ($TotEarn - 7917); $TAX = (937.50 + ($TAX * .25)); $TAX = number_format($TAX, 2, '.', ''); } for example from this: $TAX = ($TotEarn - 7917); $TAX = (937.50 + ($TAX * .25)); the output is: 1417.615 using this: $TAX = number_format($TAX, 2, '.', ''); the output was : 1417.61 but it should be : 1417.62 Thank you Bascially i add a couple numbers up and display the sum. sometimes the number is something like this: 234.237 i want it to display : 234.24 i realize its needs "round()" in it but i dont know how to use it.. any help? I am comparing 2 decimal numbers I am pulling from a mysql file for ex $row[0]==$row1[0] every once in a while i get a bad positive when I do if($row[0]==$row1[0]) when they are exactly the same? One query is a SELECT amount FROM table the other is a select SUM(amount) FROM table2 any ideas why? ive tried making them both abs() when I print the out they are = Hey, just wondering what would be the best way of adding .1 to a string. For example: Code: [Select] $newversion = $currentversion + '0.0.1'; $newversion is taken from a db, lets say for this example it is 0.2.1 This code simply outputs 0.2 Any ideas? Thanks =) I want to compute 150 + 20.95 * 1.01 + .5 so I get '171.65'. echo (150 + 20.95 * 1.01 + .5); gives me '171.6595'. I tried echo number_format(150 + 20.95 * 1.01 + .5, 2);, but I got '171.66'. How can I go about getting '171.65'? i am echoing out a value which is 1.2900 but i want it to echo out 1.29 how do i do this? cheers matt I need to round a number based on it's decimal. 3 or below should round down, 4 should round up to 5, 6 and 7 should round down to 5; 8 and 9 should round up to the next whole number. The below is returning 3 from 2.16. Code: [Select] <?php $a=2.16; $i=round($a, 1); $b=$i; $i=explode(".", $a); $decimal=$i[1]; if($decimal < 5){ $j=floor($b); $i= $decimal > 3 ? $j + .5 : $j; echo $i; } else{ $j=ceil($b); $i= $decimal < 8 ? $j - .5 : $j; echo $i; } ?> EDIT: The explode should have been on $i not $a. I'm hoping someone can show me how to get a random decimal number. I've googled and can't find anything that works. I need to find a random number between 1.0 and 10.0 I can get a random whole number no problem, but decimals aren't working. When I finally get that working, ideally I'd like to be able to find a random number between two decimals (like above) but also have a small chance of getting a decimal slightly higher than the two given. So, for example, maybe a random decimal between 3.5 and 6.0, but a slight chance of getting 6.2? Thank you very much for any help! <?php $totalcreditstd = $row_rsCreditPurchaseMoney['SUM(quantity)']; $totalcreditsdollar = $totalcreditstd * $Mutliplier; echo $totalcreditsdollar; ?> I'm using the above calculation to display a total amount. Problem is that if the calculation total is 7.5 I want it to show up as 7.50 I want to force the second number. How can I do that? Thanks. Hi I am using Zen-Cart to which I have made significant changes. Two years ago I managed to change the Products Sort Order from Integer to Decimal(5,2) to store books such as 1, 1.5, 1.75, 2 etc. Regrettably we had a major server issue and I also lost the new coding. Having restored everything else whenever we enter a book series number such as 1.5 it only stores as 1. To date the zen-Cart forums have been unable to offer a solution so I am reaching out to see if anyone else can advise me of how to get this working again please.
Thanks in advance Owen
I want to validate a form field for a number with two decimals (ie. 894567.29), but my script gives me an error, asking me to correct the entry, Following is a snippet of the script:- elseif($field == "oil_waste_ltr") { if(!preg_match("/^[0-9]{1,10}\.{2}$/",$value) ) { $bad_format[] = $field; } } Can someone five me the correct code or format to use that will allow my TINYINT columns to carry TWO decimal places when creating my table? I have a script for creating the table and columns, but only recently learned that I need to ADD the TWO decimal place FUNCTION in order to get whole dollar values to display WITH the trailing zeros (ie.:2.00). I don't expect to need any values greater than xxx.xx in my columns, I'm just not clear on how to get the desired script when running the initial CREAT script. Thanks Table Of Contents - General Description - Database Image - Code - Code - Issue I have the following code (from outside sources), which, is apparently incompatible with my co-ordinate types. Here is a database excerpt (first thirty rows) of about 9200 airports from around the world. <?php function distance($lat1, $lon1, $lat2, $lon2, $unit) { $theta = $lon1 - $lon2; $dist = sin(deg2rad($lat1)) * sin(deg2rad($lat2)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($theta)); $dist = acos($dist); $dist = rad2deg($dist); $miles = $dist * 60 * 1.1515; $unit = strtoupper($unit); if ($unit == "K") { return ($miles * 1.609344); } else if ($unit == "N") { return ($miles * 0.8684); } else { return $miles; } } $dep = $_GET['dep']; $arr = $_GET['arr']; $sql = 'SELECT * FROM `airports` WHERE `iata` = \'' . $dep . '\''; $query = mysql_query($sql); $dep = mysql_fetch_array($query); $sql = 'SELECT * FROM `airports` WHERE `iata` = \'' . $arr . '\''; $query = mysql_query($sql); $arr = mysql_fetch_array($query); echo distance($dep['latt'], $dep['long'], $arr['latt'], $arr['latt'], "k") . " km<br>"; ?> Here is my output [dep=yyz, arr=yul] with [yyz = 43.68, -79.63; yul = 45.47, -73.74] : 8719.64724823 km Obviously, with YYZ being Toronto, Canada and YUL being Montreal, Canada, it is definitely not 9000 km away (actually, ~500 km). Can you help me convert the units, or re-write the algorithms in order to make it function correctly. Thank you in advance. Hello. This is my first post here. I am not an expert developer but I generally manage to do what is asked of me. However, now and then I'm stumped, like now... I have an online database system for our company in which staff can enter JOB related data, this includes 2 dimensions which they enter in millimetres (mm). Here's an example
$dimension1 might be entered as 850 Firstly, I need to round both dimensions up to the next 100mm so the 850 in this example would become 900 and the 1447 would become 1500. Once I've done that, I need to calculate the square metres (900mm x 1500mm / 1000 was my first thought) but that raised the second thing; adding a decimal point in the result. 900 x 1500 / 1000 = 1350 but I need the result to be 1.350 I know my way around basic PHP code but I'm no expert by any stretch. If anyone can help me understand how to get this calculation done I would be hugely appreciative. Thank you Martin Hello fellow coders, I am having trouble trying to convert roman numerals to decimals (yes i know some people like to call numbers Arabic or more precisely Western Arabic.) Anyway, i cannot figure out how to allow the subtractive numbers up to and including five. I have tried several methods. Anyone have suggestions for how to deal with this problem? to be clear: MDVC for 1595 should be acceptable but MDVIIC should be invalid. I know that all converters online do not allow subtractive numbers but i want to allow them. I think that scholars have used numbers up to five in subtraction because i have not seen greater numbers being used. I have created code for converting decimals to roman numerals but i am struggling with the reverse method. I think that this is a php and logic question, not necessarily a let me see code question. For example, i was thinking that if the first number and last number are larger than all numbers between then invalid but this logic excludes MDVC. Should i scan a string for all possible invalid numbers? how does a calculus person handle this situation? there must be a math solution. I suck at math, please offer advice. I hope that this makes sense. i am tired now and sick of working on this problem. I need to clear my mind. Thank you and Best wishes. This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=326673.0 |