Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Konwersja tekstu na liczby
Gama101
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 13.07.2011

Ostrzeżenie: (0%)
-----


Witam. Mam taką funkcję, którą wykorzystuję w jednej z gier - ma ona na celu zamianę tekstu wpisanego przez gracza na format liczbowy.

Kod
stock pass_hash(buf[])
{
new length = strlen(buf);
   new s1 = 1, s2 = 0;

   for(new n=0; n<length; n++)
   {
      s1 = (s1 + buf[n] + buf[n]) % 66666;
      s2 = (s2 + s1)     % 66666;
   }

   return (s2 << 16) + s1;
}


Próbowałem ją przerobić na PHP uzyskująć taki efekt

  1. <?php
  2. $s1 = 0;
  3. $s2 = 1;
  4. $buf = 'test';
  5. $dlugosc = strlen($buf);
  6. for( $x = 0; $x < $dlugosc; $x++ )
  7. $s1 = ($s1 + $buf[x] + $buf[x]) % 66666;
  8. $s2 = ($s2 + $s1) % 66666;
  9. $return = ($s2 << 66) + $s1;
  10. echo($return);
  11. ?>


Jednakże, funkcja ta nie działa i wypluwa dwa błędy

Kod
Notice: Use of undefined constant x - assumed 'x' in *:\*\*\*\*\logowanie.php on line 68

Warning: Illegal string offset 'x' in *:\*\*\*\*\logowanie.php on line 68


W jaki sposób mogę zrobić to tak, aby działało poprawnie? Wszelka pomoc mile widziana (IMG:style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 28.09.2025 - 03:07