Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Zamiana eregi na inną funkcję
lled3
post 6.09.2018, 12:49:17
Post #1





Grupa: Zarejestrowani
Postów: 91
Pomógł: 0
Dołączył: 7.12.2007

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


Dokonałem aktualizacji PHP do wersji 7. Niestety skrypt odmówił posłuszeństwa w kilku miejscach. Ostatnim problemem z którym się borykam jest eregi(), w obsłudze płatności PayU

  1. if (eregi("<trans>.*<pos_id>([0-9]*)</pos_id>.*<session_id>(.*)</session_id>.*<order_id>(.*)</order_id>.*<amount>([0-9]*)</amount>.*<status>([0-9]*)</status>.*<desc>(.*)</desc>.*<ts>([0-9]*)</ts>.*<sig>([a-z0-9]*)</sig>.*</trans>", $platnosci_response, $parts))
  2. {
  3. $result = get_status($parts);
  4. echo'sok';
  5. }


Jakiś pomysł, jak zamienić wyłączoną w PHP 7 funkcję eregi()?
Go to the top of the page
+Quote Post
aras785
post 6.09.2018, 13:02:55
Post #2





Grupa: Zarejestrowani
Postów: 859
Pomógł: 177
Dołączył: 29.10.2009

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


preg_match?
Go to the top of the page
+Quote Post
viking
post 6.09.2018, 13:04:55
Post #3





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

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


Wchodzisz na http://www.php.net/eregi i czytasz:
Cytat
Warning

This function was DEPRECATED in PHP 5.3.0, and REMOVED in PHP 7.0.0.

Alternatives to this function include:

preg_match() (with the i (PCRE_CASELESS) modifier)


--------------------
Go to the top of the page
+Quote Post
lled3
post 6.09.2018, 17:22:43
Post #4





Grupa: Zarejestrowani
Postów: 91
Pomógł: 0
Dołączył: 7.12.2007

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


Po moich modyfikacjach kod wygląda tak:
  1. if (preg_match('/<trans>\s*<id>(\d+)<\/id>\s*<session>(.*?)<\/session>\s*<order_id>(.*?)<\/order_id>\s*<amount>(\d+)<\/amount>\s*<status>(\d+)<\/status>\s*<desc>(.*?)<\/desc>\s*<ts>(\d+)<\/ts>\s*<sig>([a-z0-9]*)<\/sig>\s*<\/trans>/si', $platnosci_response, $parts));
  2. $result = get_status($parts);
  3.  
  4. print_r($parts);


Niestety tablica jest pusta sad.gif

$platnosci_response:

  1. <?xml version="1.0" encoding="ISO-8859-2"?>
  2. <response>
  3. <status>OK</status>
  4. <trans>
  5. <id>1111111111</id>
  6. <pos_id>2222222222</pos_id>
  7. <session_id>5b90e4</session_id>
  8. <order_id>5b90e/order_id>
  9. <amount>2325</amount>
  10. <status>99</status>
  11. <pay_type>o</pay_type>
  12. <pay_gw_name>pe</pay_gw_name>
  13. <desc>cukiernia@domena.pl</desc>
  14. <desc2></desc2>
  15. <create>2018-09-06 10:27:25</create>
  16. <init>2018-09-06 10:28:24</init>
  17. <sent>2018-09-06 10:28:25</sent>
  18. <recv>2018-09-06 10:28:25</recv>
  19. <cancel></cancel>
  20. <auth_fraud>0</auth_fraud>
  21. <ts>1536251379151</ts>
  22. <sig>b5a5a07f6198a778100adddf</sig>
  23. <add_client_street></add_client_street>
  24. <add_client_post_code></add_client_post_code>
  25. <add_client_address></add_client_address>
  26. <add_client_account>53124027601608</add_client_account>
  27. <add_cc_number_hash>ab7205a7e780824537516</add_cc_number_hash>
  28. <add_client_name></add_client_name>
  29. <add_client_city></add_client_city>
  30. </trans>
  31. </response>


Ten post edytował lled3 6.09.2018, 17:33:03
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 16.04.2024 - 11:44