Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Everything posted by jodunno

  1. interesting. I can't believe that my code is even remotely similar to yours. I am not a very good programmer so it is nice to know that i did something correctly. I suppose that i am a bit too hard on myself. Really though, i am still trying to comprehend how i wrote code that is similar to your code. You are a pro and i am just a programmatic idiot trying to make a website. I guess i am slowly learning how to think programmatically. So progress is good 😀 but i don't let it go to my head. I got lucky this time and did something right. I am going to get some coffee and get to work on my roman to decimal converter.
  2. Hi Barand, I created a script for decimal to roman last week. I am certain that my approach is different than yours but i get the job done. I added a loop so that my code prints numerals 1-3999. Decimal to Roman is easy if we only convert to standard Roman numerals. Converting from unknown possibly nonstandard possibly invalid roman numerals to decimal is a bit more difficult. I suppose that one could make a 3999 roman numeral valued array and call it a day but i like to try to solve the problems programmatically. If failure happens and i can't find a way to filter correctly then the 3999 value array is my only hope. Here is my Decimal to Roman converter using basic arithmetic of places. Everyone, take your places! 😃 <?php //John's PHP Decimal number to Roman Numeral converter v1 $Ones = array('I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'); $Tens = array('X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'); $Hundreds = array('C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'); $Thousands = array('M', 'MM', 'MMM'); for ($j = 1; $j < 4000; $j++) { $PlaceCount = strval(strlen($j)); $Places = str_split($j); $RomanNumeral = null; switch ($PlaceCount) { case '1': $RomanNumeral = $Ones[$j - 1]; break; case '2': $RomanNumeral .= $Tens[$Places[0] - 1]; if (!empty($Places[1])) { $RomanNumeral .= $Ones[$Places[1] - 1]; } break; case '3': $RomanNumeral .= $Hundreds[$Places[0] - 1]; if (!empty($Places[1])) { $RomanNumeral .= $Tens[$Places[1] - 1]; } if (!empty($Places[2])) { $RomanNumeral .= $Ones[$Places[2] - 1]; } break; case '4': $RomanNumeral .= $Thousands[$Places[0] - 1]; if (!empty($Places[1])) { $RomanNumeral .= $Hundreds[$Places[1] - 1]; } if (!empty($Places[2])) { $RomanNumeral .= $Tens[$Places[2] - 1]; } if (!empty($Places[3])) { $RomanNumeral .= $Ones[$Places[3] - 1]; } break; } echo $RomanNumeral . '<br>'; } ?>
  3. Hi Barand, Thank you for the lovely gift 🙂 I will finish testing today. I have a physical therapy session in the afternoon. Hopefully, i can put it all together after my appointment. I think that the program is working as expected but time will tell. Best wishes, John
  4. Hi gw1500se, i don't know how to define the scholarly subtraction but it certainly isn't invalid. Some mathematicians (which noone has ever heard of) suddenly hold themselves higher than, say Carl von Linne, and deem MDVC as an invalid numeral. However, some of the world's smartest people have published books with these 'invalid' numerals. I want to convert these numerals that you may see in old books and not show a message that it is invalid. I have only seen numbers I-5 used in irregular subtraction dates: mdvc, mdic etc. I've not seen MDVIIC or MDVIXC. I want to limit irregular subtractions to five while ignoring any other subtractions until later in the code. I like the limit and i want the limit. I have the limit. Filter number 2 handles these lower numbers used in irregular subtractions: //2. subtraction less than 5 should be valid in this converter $validSubtraction = array('IV', 'III', 'II', 'I', 'V'); foreach ($validSubtraction as $m) { foreach ($FollowedBy as $n) { $pos = stripos($RomanNumeralInput, $m . $n); if ($pos !== false) { // if ($m === $n) { $invalid = 1; $invalidRule = 20; break(2); } if ($pos > 0 && $RomanNumeralInput[$pos-1] === 'I') { $invalid = 1; $invalidRule = 21; break(2); } if ($pos > 0 && $RomanDecimal[$RomanNumeralInput[$pos-1]] < $RomanDecimal[$n]) { $invalid = 1; $invalidRule = 22; break(2); } $subtraction = 1; $subtractionCount = strlen($m . $n); $subtractionIsolated = $m . $n; $calculateSubtraction = $RomanDecimal[$n] - $RomanDecimal[$m]; if ($pos + $subtractionCount < strlen($RomanNumeralInput)) { if ($calculateSubtraction > $RomanDecimal[$RomanNumeralInput[$pos + $subtractionCount]]) { $invalid = 1; $invalidRule = 23; break(2); } } $RomanNumeralInput = str_replace($m.$n, '', $RomanNumeralInput); break(2); } } } if ($invalid) { echo ' is a nonstandard Roman Numeral (Rule number: ' . $invalidRule . ')'; exit; } This code works. Later, i handle all other subtractions like everyone else. loop through the array holding the submitted numeral. Then simply use an if statement. If current numeral less than next numeral, then subtractive. I have tried my code on numbers 1-100, 200, 300, 400, 500, 1000, 3999, MDVC etc. I have no problems yet. MDCM is handled normally in my code. I will finish the code tomorrow, then loop through 1-3999 and see how it goes. Then i will try various irregular combinations and see how the code holds up. I'll post reults. Maybe someone can help clean up and tighten my code. Best wishes, John
  5. ixx really shouldn't be calculated and my code skips it. I prefer it be skipped. Furthermore, i notice other numerals that should be ignored according to research and comparison with printed material: vv,vvv,vvvv, ll,lll,llll, dd,ddd,dddd. 2021 really should not be processed as dddixxii. I also noticed that old books use the letter j for a final i in a series of this numeral: ij, iij, vij, viij. I've added this snippet of code to my program to permit the usage of the letter j: $RomanNumeralInput = str_replace('J', 'I', $RomanNumeralInput); I added the following code at the end of my script (after Isolation so that subtractive numbers are not factored) to block repeated characters above four times (three is the standard but i've seen iiii and cccc in published material): //3. check for numerals repeated greater than four times and exclude L,D foreach (count_chars($RomanNumeralInput, 1) as $i => $val( { if ($val > 4) { $invalid = 1; $invalidRule = 30; break; } if ($val > 1 && $val <= 4 && chr($i) === 'L' || chr($i) === 'D') { $invalid = 1; $invalidRule = 31; break; } } // show error message and rule violation which helps during development process. if ($invalid) { echo $RomanNumeralInput . ' is a nonstandard Roman Numeral. (Rule number: ') . $invalidRule . ')'; exit; } I really just wanted a date converter that accepts subtractions up to V (MDVC) and permits repeated numerals up to four times (IIII, CCCC). I also wanted to block irregular and nonstandard numerals. One can argue that VC is non standard but it is published in old books. Thus, i aim to create a converter that will help users convert the numerals that they may see in old books. I am getting closer to completing my code. Adding J is also something that i want to support. I am going to add the conversion soon, then see how it handles conversions from 1-to-3999 along with subtractions. Your code is clean and efficient for sure. I need to learn how to be a better coder. I am just adamant about sticking to my design. I don't want to process ixx, viiiviii, vvvv, ixi, etc. Best wishes, John
  6. Hi Barand, I got my program to do all of the tings that i want it to do. I just have to finish the code by producing a decimal/arabic number and verify that all of the numbers are correct. I have learned something about Roman numerals today that i find interesting. I do not rmember hearing about this problem before. I have given this problem a name: "The Nine Hole". Your code also falls into the "Nine Hole". What am i talking about? how do you know that ixx is 19 and not 1? ixx is 10-9 or 20-1, depending on how you see it. My code jumps over the Nine Hole with a code block on the ix as an invalid subtraction followed by ten. Your code calculates 19. I never thought about this problem before. I didn't realize that such a problem exists. Do you see it? ix, iix, iiix, ivx, vx, vix, viix, viiix, ixx (also 20-1). I have decided to keep my "jumping over the Nine Hole code", which i will also explain on my website. Meantime, i am satisfied with my code for now. I will try to wrap it up later or tomorrow. Then i will test it with numbers 1-3999. Then i will test it with odd and irregular numerals. If everything works as expected , then i am finished wih this nightmare of a project. And i will have a converter which accepts subtractive numbers up to five. Best wishes, John
  7. Hi Barand, I am not making a calculator. I will try to better explain my project. I am simply trying to create my own date converter (roman numerals to arabic/decimal numbers) allowing common date subtractive numerals but restricting subtractives to five. Again, I forgot how roman numerals work except for basic numers. I had to look up D (500) for example. I often have to calculate the dates in books for my literary references of biographical notices. An example citation for Ulisse Aldrovandi (Ulysses Aldrovandi): Bonucci, Anicio . Plauso Letterario per la Restaurazione della Sala Urbana ed Inaugurazione dell'aula Piana nel Palazzo Apostolico di Bologna . Artikel: Elogio di Ulisse Aldrovandi . Seiten 68-73 . Bologna (Italien) 1852 (M DCCC LII) I often have to mentally convert the dates because they are only published in Roman numerals. I started using online converters to spare me from having to calculate. But none of the online converters that i found allow subtractive numbers. I found an old book from 1595 and the published date was in Roman Numerals as MDVC. I couldn't find an online converter that accepts this format. Again, i've seen subtractive numbers in books but they seem to stop at 5. I've not seen viic, so it appears to me that old scholars accepted subtractive dates with a limit of five. I want to permit these subtractions but stick to conventional numerals for all other dates. Thus viiiviii is not conventional and i'd like to ignore it. I further tweaked my code and it is now blocking the following numerals: xicx, ixcx, iiilxv, viiiviii. So my code seems like it is working now. My code accepts MDVC but not MDVIIC. I am happy. It is actually working. Meantime, i hope that i can list links here. I am certainly not spamming, endorsing or advertising. If the following links are deemed inappropriate then have a mod delete them and i am sorry. So these are the sites that i was using for quick date conversions (none of the sites accept mdvc, which is annoying): www.romannumerals.org/converter www.calculatorsoup.com/calculators/conversions/roman-numeral-converter.php www.rapidtables.com/convert/number/roman-numerals-converter.html I thought that it will be nice to make my own converter for my website but tweak it to accept common subtractive numerals in dates. Like mdvc. By the way, i cant visit the rapidtables site anymore unless i use kmeleon browser. LOL. i got mad at youtube for the ad bombardments that i get lately. I decided to remove my adblocker ublock origin and go for the kill. I installed tinywall open source browser, installed fiddler, and editied the fiddler HOSTS list since Microsoft erases any changes that i make to my system HOSTS file. I am also sick of MS updates interrupting me. I blocked Windows Updates, Mozilla communications, telemetry and ad sites/uris. I blocked youtube ads and popups. Which reminds me, i also enabled custom css in Firefox to remove annoying css cookie overlays since websites are trying to detect ublock and nag me about it. I went back to private filtering (fiddler, custom css and firewall). Now cloudflare tries to deem my system as a security threat. I should sue them because they are the threat. I don't have to set up my system for ads, tracking and espionage or be labelled a security threat. I'm mad. These tech companies go too far. Anyway, now my stsem is tight and rapidtables is not functioning (fiddler shows why). Thus lately, i've been using calculatorsoup instead. While waiting for my own converter to be fully operational.
  8. yes i see how it reaches ten but viiiviii is getting too far away from my goal. I suppose that i am trying to create a copyright year converter and not an addition and subtraction calculator. Which is why i say that viiiviii is not valid. Remember that my site is biology/nature related. I've added biographical notices (place of birth/death, profession etc.) I list books as references. Alot of books are very old (1400s, 1500s, 1600s, 1700s and 1800s). Alot of copyright dates are roman numerals and they do not contain non standard forms, such as vvvv for 20. My goal was emulate online calculators with a common subtractive exception. I added a loop to my code that checks the numbers in a reversed array, thus allowing me to query if current number is less than next number then invalid. VIIIVIII gets blocked in this code. I can further retsrain repetition by only permitting certain numbers to be repeated and only 3 times. Example, CCC and III but CCCC and IIII will be blocked. I'm getting a better grip now the picture is getting clearer.
  9. I was thinking about this whole problem and all of my coding attempts. I wondered how my code would handle repetition, so i tied it and my code failed to detect it. So i tried it using your script and your script also accepts it but oddly calculates the amount. I tried VIIIVIII. Your script outputs 10. I would think it should be 16 but technically an invalid number. This is so complicated.
  10. so i take that to mean a fee of my choosing? How about a pint 😁 just kidding. Although, as legal notice, posting the code in public is not a consent to usage of said code. Afterall, you are the copyright holder. I can post a copyright photo here but it does not grant legal rights to use it. Too many people use other peoples work illegally. I am not one of those people. I can analyze your logic and work it into mine but certainly not in part or in whole. I forgot to say Thank you for all of your time and hard work. In fact, Thank you to everyone posting in this thread. I appreciate you and this community. Best wishes, John
  11. well your code is very nice and seriously professional. The only negative aspect to your code is the calculation of non stadard numerals but noone should really care. However, it is your code not mine. I can't legally use someone elses code in a commercial application. Remember that my website is commercial. I'm not a thief, Sir. :-) I respect you and your intellectual property.
  12. Hi Barand, my new code post was the first attempt at isolation. The script is unfinished in the post. However, i just added the missing factors. My latest script appears to work as expected but i haven't tested every number combo. I got started on this because i actually saw an old book with MDVC and i didn't know how to calculate that. I was introduced to subtractive roman numerals at that point. I couldn't even remeber what D was (now i know it is 500). I don't use Latin numbers. Anyway, my first thought was to use an online converter for the MDVC but they all rejected this number as invalid. I yelled at the screen "BUT I SEE IT IN AN OLD BOOK'. LOL. I decided that i want to add a roman numeral converter to my site that allows subtractive Roman numerals. However, i have not seen subtractive numbers greater than 5 and really it doesn't make sense to write VIIX instead of III. I can understand MDVC but not MDIXC because it would be easier to write MDCI. I wanted to control the subtraction to five. Anyway, here is my latest code which also checks for my so-called valid subtraction and adds it to the final array. It seems to be working... <?php //limit 3999 or MMMCMXCIX $RomanNumeralInput = strtoupper('xiix'); //XICX ixcx MDIIC $RomanDecimal = array('I' => 1, 'IV' => 4, 'V' => 5, 'IX' => 9, 'X' => 10, 'XL' => 40, 'L' => 50, 'XC' => 90, 'C' => 100, 'CD' => 400, 'D' => 500, 'CM' => 900, 'M' => 1000); $invalid = $subtraction = $subtractionCount = $subtractionIsolated = $append = 0; echo $RomanNumeralInput . '<br>'; $Subtractive = array('IX', 'VIII', 'VII', 'VI'); $FollowedBy = array('X', 'L', 'C', 'D', 'M'); foreach ($Subtractive as $n) { foreach ($FollowedBy as $m) { $pos = strpos($RomanNumeralInput, $n . $m); if ($pos !== false) { $invalid = 1; break(2); } } } if ($invalid) { echo ' is a nonstandard Roman Numeral'; exit; } $validSubtraction = array('IV', 'III', 'II', 'I', 'V'); foreach ($validSubtraction as $m) { foreach ($FollowedBy as $n) { $pos = stripos($RomanNumeralInput, $m . $n); if ($pos !== false && $m . $n !== 'IX') { $subtraction = 1; $subtractionCount = strlen($m . $n); $subtractionIsolated = $m . $n; $RomanNumeralInput = str_replace($m.$n, '', $RomanNumeralInput); break(2); } } } $Isolation = array(); if (!empty($RomanNumeralInput)) { $RomanNumeral = str_split($RomanNumeralInput); $PlaceCount = count($RomanNumeral); if ($pos >= $PlaceCount) { $append = 1; unset($pos); } $count = 1; $stringcount = 0; $skip = 0; foreach ($RomanNumeral as $i) { if (isset($pos) && $stringcount === $pos) { array_push($Isolation, $subtractionIsolated); unset($pos); } if ($skip) { $skip = 0; $count++; $stringcount++; continue; } if ($count < $PlaceCount) { if ($RomanDecimal[$i] < $RomanDecimal[$RomanNumeral[$count]]) { array_push($Isolation, $i . $RomanNumeral[$count]); $count++; $stringcount++; $skip = 1; continue; } array_push($Isolation, $i); $count++; } else { array_push($Isolation, $i); } $stringcount++; } if ($append) { array_push($Isolation, $subtractionIsolated); } } else { array_push($Isolation, $subtractionIsolated); } echo '<br>'; print_r($Isolation); ?> the XICX is still irritating me. Which is why i keep trying to exclude it. It really is a strange non standard roman numeral. It annoys me like a mosquito. even ixcx but my latest script denies ixcx.
  13. Good morning, I have been thinking endlessly about this problem. I started to realize that one roadblock to understanding a roman numeral is a lack of isolation. I have no idea if a subtractive number exists or not. Thus, i was thinking that if we can separate paired numbers (VII or IX) versus singular numbers (X, M, C etc) then we will have a way to know what we are dealing with. Yet, i don't think that we need to isolate additive pairs (VI, VII etc.) because they will correctly be handled via addition from isolation. Thus, i have tried a quick script for subtractive isolation and used my previous code to detect a non standard subtraction. I need an opinion about this method. Do you think that it is a good idea? could this help us solve the problem? here is my new code which isolates numbers excluding non standard subtraction. Tell me what you think, please. <?php //limit 3999 or MMMCMXCIX $RomanNumeralInput = strtoupper('MMMCMXCIX'); //XICX ixcx $RomanDecimal = array('I' => 1, 'IV' => 4, 'V' => 5, 'IX' => 9, 'X' => 10, 'XL' => 40, 'L' => 50, 'XC' => 90, 'C' => 100, 'CD' => 400, 'D' => 500, 'CM' => 900, 'M' => 1000); $invalid = 0; $Subtractive = array('IX', 'VIII', 'VII', 'VI'); $FollowedBy = array('X', 'L', 'C', 'D', 'M'); foreach ($Subtractive as $n) { foreach ($FollowedBy as $m) { $pos = strpos($RomanNumeralInput, $n . $m); if ($pos !== false) { $invalid = 1; break(2); } } } if ($invalid) { echo $RomanNumeralInput . ' is a nonstandard Roman Numeral'; exit; } $RomanNumeral = str_split($RomanNumeralInput); $Isolation = array(); $PlaceCount = count($RomanNumeral); $count = 1; $skip = 0; foreach ($RomanNumeral as $i) { if ($skip) { $skip = 0; $count++; continue; } if ($count < $PlaceCount) { if ($RomanDecimal[$i] < $RomanDecimal[$RomanNumeral[$count]]) { array_push($Isolation, $i . $RomanNumeral[$count]); $count++; $skip = 1; continue; } array_push($Isolation, $i); $count++; } else { array_push($Isolation, $i); } } print_r($Isolation); ?> so now that numbers are isolated, we could have a better shot at analyzing the number for non standard input. right? Best wishes, John
  14. I'm going to call it a day now. I am tired and my arm is hurting. I want to relax a bit before bed. I hope that you, Barand, and everyone else has a splendid day (or evening or night). Best wishes.
  15. I can see that smaller numbers before and after larger numbers with subtraction could be invalid but i have no idea how to code that concept with all of the other concepts smashed into the equation. By the way, here is the code that i worked on this morning. LOL it is so kindergarten like compared to your code. As you can see, i just battle with code that i know to accomplish what i'm trying to do. I'm not at your level for sure. LOL <?php //limit 3999 or MMMCMXCIX $RomanNumeralInput = strtoupper('XICX'); //XICX $RomanNumeral = strtoupper($RomanNumeralInput); $Ones = array('I' => 1, 'II' => 2, 'III' => 3, 'IV' => 4, 'V' => 5, 'VI' => 6, 'VII' => 7, 'VIII' => 8, 'IX' => 9); $Multiples = array('X' => 10, 'XL' => 40, 'L' => 50, 'XC' => 90, 'C' => 100, 'CD' => 400, 'D' => 500, 'CM' => 900, 'M' => 1000); $MultiplesR = array('IX', 'XL', 'XC', 'CD', 'CM'); $Filter = array_merge($Ones, $Multiples); $invalid = $total = $add = $subtract = 0; foreach ($MultiplesR as $m) { $pos = strpos($RomanNumeralInput, $m); if ($pos !== false) { $RomanNumeral = str_replace($m, '', $RomanNumeral); $add += $Filter[$m]; } } $validSubtraction = array('IV', 'III', 'II', 'I', 'V'); $FollowedBy = array('X', 'L', 'C', 'D', 'M'); foreach ($validSubtraction as $m) { foreach ($FollowedBy as $n) { $pos = strpos($RomanNumeral, $m . $n); if ($pos !== false) { $RomanNumeral = str_replace($m, '', $RomanNumeral); $subtract += $Ones[$m]; break(2); } } } $invalidSubtraction = array('I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'); foreach ($invalidSubtraction as $m) { foreach ($FollowedBy as $n) { $pos = strpos($RomanNumeral, $m . $n); if ($pos !== false) { $invalid = 1; break(2); } } } $RomanNumeral = str_split($RomanNumeral); $PlaceCount = count($RomanNumeral); $count = 1; foreach ($RomanNumeral as $i) { $add += $Filter[$i]; } if (!$invalid) { $total = $add - $subtract; echo $RomanNumeralInput; echo '<br>'; echo $total; } else { echo 'invalid number'; } ?>
  16. Hi Barand, I hope that you are doing well. I haven't been here alot lately due to an operaion. I didn't forget about you. I allready know that you are a top notch programmer and the code that you have posted illustrates this statement. However, and trying to not seem ungrateful, there is still a problem which exists even in your functions. Let me explain, today i tried to work on this problem and i got a working solution (which is horrible compared to your code). Then i accidentally copied and pasted IC between XX, thus attempting to convert XICX. Again, it was completely by accident. My - thought to be working code - actually converted this number, which should be invalid. Your program also converts this number. I am about to give up on this idea. I can't seem to define what is valid versus invalid. I'm certain that Donald Knuth could conjure a solution but i am unable to do so with my poor math skills. And really, my logic skills are not too impressive either since i can't see a way to define even an invalid number. I thank you for your code contribution. I will either give up on this and accept the fact that invalid numbers will still be processed or i will work on this slowly as a side project. Best wishes.
  17. Hi gw1500se, Thank you for taking time to dig up this code, it is very helpful code. I have been so busy battling this concept and i forgot about validation. Excellent contribution! Much appreciated. I am done battling for the day. I have an early appointment in the morning. I had an operation on my arm and i have a check up. Part of this code problem is my arm. I cannot use my mouse very much and typing creates pain. I am right handed and the surgery was on my right arm. Anyway, I go to bed soon (time difference here in Deutschland.) Although i still keep American time on my system. Best wishes and Good night everyone. I'll try again tomorrow.
  18. okay, so here is my last attempt. @Barand my current code allows MCM, filters MDVIIIC but allows MDVC. Now the problem is that MDIC fails. I'm missing something and stupidly so. Maybe other eyes and minds can help me nail this? <?php //limit 3999 or MMMCMXCIX $RomanDecimal = array('I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000); $total = $add = $subtract = 0; //if L C D or M follow any V followed by one or more ones, then invalid //invalid before L C D or M: VI, VII, VIII, IX $RomanNumeral = 'MCM'; $Subtractive = array('IX', 'VIII', 'VII', 'VI'); $FollowedBy = array('L', 'C', 'D', 'M'); foreach ($Subtractive as $n) { foreach ($FollowedBy as $m) { $pos = strpos($RomanNumeral, $n . $m); if ($pos !== false) { $invalid = 1; break(2); } } } if (!empty($invalid)) { echo 'invalid number'; exit; } echo $RomanNumeral . '<br>'; $RomanNumeral = str_split($RomanNumeral); $PlaceCount = count($RomanNumeral); $count = 1; $total = 0; foreach ($RomanNumeral as $i) { if (!empty($skip)) { $skip = 0; $count++; continue; } if ($count < $PlaceCount) { if ($RomanDecimal[$i] < $RomanDecimal[$RomanNumeral[$count]]) { if (in_array($RomanDecimal[$RomanNumeral[$count]], $FollowedBy)) { $subtract += $RomanDecimal[$i]; $count++; continue; } if ($RomanDecimal[$i] == $RomanDecimal[$RomanNumeral[$count]]) { $subtract += $RomanDecimal[$i]; $subtract += $RomanDecimal[$RomanNumeral[$count]]; $count++; $skip = 1; continue; } $subtract += $RomanDecimal[$i]; } else { $add += $RomanDecimal[$i]; } } else { $add += $RomanDecimal[$i]; } $count++; } $total = $add - $subtract; echo $total; ?>
  19. Hi Requinix, i'm trying to avoid trouble and not ask for code help. I am sorry that my mind is unable to grasp this right now. I apologize for having to ask for help but i am so mentally tired. I can't see the answer right now. I'm doing something wrong. Before i post my code (i have to fetch it from my other pc, i'll be right back), i want to tell everyone that i have it allowing MDVC and rendering MDVIC or MDVIIC etc as invalid. but now my childish rules are blocking MDIC and MDIIC and MDIIIC. I am missing something simple here and i just can't grasp it. I'm getting very frustrated. Thank you all for trying to assist me despite my poor programming skills. I shall return with my latest filtering attempt.
  20. Hello gw1500se, Thank you for taking time to assist me. I appreciate it very much. I saw those posts at stackoverflow when i searched google for examples. I tried a few and the results are the same as my attempts at filtering subtractive numbers: not working. For example, MDVIIC should be invalid but it is an invalid method of specifying 1593 but ait is handled in code as 1605. My code does the same thing. Is it stupid of me to think that a valid number array versus invalid number array is the best route here? i was wondering if i need to tell my code was is valid versus invalid and go from there. Perhaps there is no easy way to do this. Best wishes.
  21. Hello gw1500se, The code on the linked site is for converting decimals to roman numerals. I all ready created code for that. I used a different method for this conversion. I mapped all of the roman numbers by places, then split the number by places and display the corresponding numeral in its correct decimal place. Ones, Tens, Hundreds or Thousands. Anyway, now i want to convert roman numbers into decimal numbers but still allow subtracive roman numbers up to and including five. Thus, MDVC for 1595 (M=1000, D=500, 100-5 - 95 or VC) instead of the normal Roman number for 1595 (MDXCV). I want to allow both forms in the conversion but disallow subtractive numbers greater than 5 (so MDVIIC is invalid for 1593). I can't figure out how to accomplish this task. I can only figure out how to disallow all subtractive numbers. Best wishes and Thank you for reading and trying to offer help. :-)
  22. 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.
  23. Good morning kicken, my filter is for use with login attempts. I am actually working on my own character map. so Smythe-Jones will be Smythe[hyphen]Jones in my database. Thus, all non alphabetic characters submitted via post will be converted/mapped before application. 12.25 will become 12[point]25. permissible is indicative of your disposition. Interesting mindmap. I'm not really ranting. For one thing, i like Barand and generally everyone in this forum. However, people need to stop making excuses for the wild west approach to internet and programming. It is time to implement law and enforcement to code and internet in general.
  24. if i only accept letters from the English alphabet, then yes. My post concerns login attempts not registration. During registration: if (!ctype_alpha($untrustedData)) { //log error for display, such as usernames may only contain characters from the English alphabet } on my website, i permit hyphen, apostophre but we are talking about sanitizing code and how to accomplish it. If someone wants to add an array of acceptable characters, then they can do so. Simply add !in_array() check to the loop. However, i hope that you are not one of these lawless internet folks that actually think you should be able to do whatever you want to do without laws. Face it, you must obey laws everyday and it is time that the internet keeps up with society. For one thing, a username and display name are different concepts. I actually enforce both. You will log in with your username (and i allow hyphens and other characters), password (16-224 characters) and email (that's right, i add a third requisite for you to try to brute force). Your display name wil be used on the site in place of your [supposed to be secret]username. I am the Commander-in-Chief of my website and those are my rules. Don't like it? then go somewhere else. You can't legally walk into a bank wearing a ski mask with a gun in your hand and you can't type whatever you want to type on my freekin website either :-) I honestly don't care about whiners. I've had enough with website hacking and making it easy for these individuals to inject. Narrow minded means only seeing why you can't force the use of an useless hphen. Clinging to a non speakable character and refusing to see any other point-of-view is narrow minded. Really, i don't need accent marks to log you in to my website.I only need them to instruct me to correct pronunciation. I think that everyone online should have to login to websites through a government controlled id system. No more anonymity. Hackers have had it too easy and it's time to put an end to it. We all have to provide id to police when asked, by law, and we should all have an internet id as well. And website owners should never be able to see that id. The ids should be checked through a gov controlled access point. Similar to a credit card processing system. However, we will also need laws to protect id holders from fraud. Protection, in my opinion, also includes marketing and advertising. Tech companies should not be permitted to know your id and use it for advertising and marketing purposes. Meantime, the original poster asked for ideas of how to sanitize without specific details. My example just shows how to enforce alphabetical characters (a hypothetical scenario) and discard all others. My code is actually for login attempts and not registration. The code can easily be tweaked to accomodate various scenarios. At the end of the day, preg match is a p-i-t-a and very few times will anyone help with preg-match code. My point-of-view mocks nature: consider a night club scenario with a bouncer: the club doesn't open the doors like flood gate and yell everyone do whatever you want and enter like a stampede. We have lines and each person must provide id to enter the nightclub. I take it a step further and say all ids will be checked with police for authenticity (fake ids).
  25. I agree with mac_gyver. pdo is simple and better. Meantime, you should always program in a definitive manner whenever possible. So know what you want and enforce it. Thus, if you only want usernames to contain alphabetic letters, then enforce it. Only deal with what is allowed and throw everything else in the programmatic trash can. like so: $untrustedData = $_POST['username']; //trim will not remove spaces between letters, which can sometimes happen as a typo/typing error $untrustedData = str_replace(' ', '', $untrustedData); if (!ctype_alpha($untrustedData)) { $splitkey = (array) str_split($untrustedData); $untrustedData = ''; foreach ($splitkey as $index => $letter) { if (!ctype_alpha($letter)) { continue; } $untrustedData .= $letter; } } now user123<script>name will become userscriptname and that is that. Nothing to inject. Along with pdo, you are quite safe from common sql injection attacks. I always enforce my rules and discard everything else when dealing with untrusted data. Some coders might hate my method but it works well for me. alphabetic characters or hit the bricks. 🙂 Best wishes.
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.