arrays - How do I "add" strings in PHP - not concatenate, but "add" them. (as if each character was a base 36 numbers) -


Unfortunately, I inherited some code (C / C ++) that manipulate some strings and now I need to copy / port it on. Php can therefore be accessed on this functionality internets

Specifically the functionality takes some arbitrary strings and combines them together "(C code repeats the character array and then to make sure Some checks out that they are in alphanumeric category)

I can not find specific code examples on how to do this (I am not a PHP developer) - did anyone tell me some resources Could that explain it? (How to manipulate the string / character array originally)

Edit

In response to some comments and replies: I want results in ASCII, but essentially I have a base 36 I'll add the number. C code is now converted to base 36 (ASCI), then connects each element together (does not take it - though the original author had intended - and it "adds" to some weird reason "from the most important to the least ) Then the converts converts to ascii back can be from different lengths

Based on the existing answers, I think I have enough requirements for this. Sometimes it is frustrating to learn a new language - you know what you want and you can do it in other languages, not just one thing ...

Thanks for yet.

Can not you () do it?

  $ sum = base_convert ($ str1, 36, 10) + base_convert ($ str2, 36, 10); $ Sum36 = base_convert ($ sum, 10, 36);  

Or do you need precision arbitrarily? In addition to arbitrarily precision here, base in 36:

  function b36_add ($ str1, $ str2) {$ to10 = array (); {$ To10 [base_convert ($ i, 10, 36)] = $ i; for $ ($ I = 0; $ i & lt; 36; ++ $ i) } $ Len = max (strlen ($ str1), strangel ($ str2)); $ Str1 = str_repeat ('0', $ len - strlen ($ str1)) $ Str1; $ Str2 = str_repeat ('0', $ len - strlen ($ str2)). $ Str2; $ Pos = $ len - 1; $ Move = 0; $ Sum = ''; Do {$ tmp = base_convert ($ move to $ to10 [$ str1 [$ pos]] + $ 10 [$ str2 [$ pos]], 10, 36); $ Sum = Substr ($ tmp, -1); $ Carry = (int) substate ($ tmp, 0, -1); } While (- $ pos> = 0); $ Sum = strrev ($ sum); If ($ LE) {$ sum = base_convert ($ LE, 10, 36) $ amount; } Refund Amount; }  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

php - Multiple Select with Explode: only returns the word "Array" -

php - jQuery AJAX Post not working -