Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [wyrazenia regularne] Zmienne w themie..., ... z tablicami
bim2
post 26.06.2006, 07:04:58
Post #1





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


Witam. Mam problem. Kombinuje z kumplem jak rozbić sobie np. {ZMIENNE:tablica:tablica2:tablica3...}
Mozna to zrobić funkcja preg_replace_Callback (explode(':'..., układać jak sie da i eval()) ale to jest wolne ohmy.gif
Dlatego chciałbym spytać się czy ktoś nie zna sposobu na jakieś inne rozbicie tejże zmiennej. (tablic w zmiennej może być w nieskończoność) aarambo.gif Mnie to przerosło worriedsmiley.gif


--------------------
Go to the top of the page
+Quote Post
Kirtan Loor
post 26.06.2006, 07:35:07
Post #2





Grupa: Zarejestrowani
Postów: 44
Pomógł: 0
Dołączył: 22.10.2004
Skąd: Płock

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


  1. <?php
  2. preg_match_all("#:(S+)#", $zmienne, $arrays);
  3.  
  4. for( $i=0;$i<count($arrays[1]);$i++ )
  5. {
  6.  #....
  7.  eval($arrays[1][$i]);
  8. }
  9.  
  10. # ewentualnie
  11.  
  12. foreach( $arrays[1] as $tab )
  13. {
  14.  #...
  15.  eval($tab);
  16. }
  17. ?>


Hmm nie jestem pewien czy o to ci akurat chodzilo.


--------------------
A Chartreux et à Célestins, A Mendiants et à Dévotes,
A musards et claquepatins, A servants et filles mignottes
Portants surcots et justes cottes,A cuidereaux d'amour transis,
Chaussant sans méhaing fauves bottes, Je crie à toutes gens mercis.
Go to the top of the page
+Quote Post
bim2
post 26.06.2006, 07:36:00
Post #3





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


Napisałem że tak umiem. Chodzi bez evala bo zmniejsza mi 30% szybkości parsera sad.gif Bez evala tongue.gif


--------------------
Go to the top of the page
+Quote Post
Kirtan Loor
post 26.06.2006, 07:37:08
Post #4





Grupa: Zarejestrowani
Postów: 44
Pomógł: 0
Dołączył: 22.10.2004
Skąd: Płock

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


Tobie chodzi o eval czy o wybieranie ze {ZMIENNE:...} tablic?


--------------------
A Chartreux et à Célestins, A Mendiants et à Dévotes,
A musards et claquepatins, A servants et filles mignottes
Portants surcots et justes cottes,A cuidereaux d'amour transis,
Chaussant sans méhaing fauves bottes, Je crie à toutes gens mercis.
Go to the top of the page
+Quote Post
bim2
post 26.06.2006, 07:39:17
Post #5





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


O wybieranie ale bez eval tongue.gif Zeby z {ZMIENNA:1:2:3:4}
było $ZMIENNA[1][2][3][4] chodzi o przetworzenie biggrin.gif. Czyli jak podam np {config:db:user} i mam zmienna $config[db][user] to {config:db:user} zamieni sie na warrtosc $config[db][user] biggrin.gif


--------------------
Go to the top of the page
+Quote Post
Kirtan Loor
post 26.06.2006, 07:45:02
Post #6





Grupa: Zarejestrowani
Postów: 44
Pomógł: 0
Dołączył: 22.10.2004
Skąd: Płock

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


  1. <?php
  2.  
  3. $zmienne = '{user:db:config}';
  4.  
  5. preg_match_all("#:(S+)#", $zmienne, $arrays);
  6.  
  7. # musisz sobie wybrac nazwe zmiennej;
  8. $name = 'user';
  9.  
  10. $zm = '$'.$name;
  11.  
  12. foreach( $arrays[1] as $tab )
  13. {
  14.  $zm .= '['.$tab.']';
  15. }
  16.  
  17. eval($zm);
  18.  
  19. ?>

Wtedy masz teoretycznie tylko jeden eval... Bo bez w ogole to nie potrafie ci pomoc.;-) Nie jestem nawet pewien czy to zadziala;-)


--------------------
A Chartreux et à Célestins, A Mendiants et à Dévotes,
A musards et claquepatins, A servants et filles mignottes
Portants surcots et justes cottes,A cuidereaux d'amour transis,
Chaussant sans méhaing fauves bottes, Je crie à toutes gens mercis.
Go to the top of the page
+Quote Post
bim2
post 26.06.2006, 08:33:28
Post #7





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


Wrrr mad.gif Mówie że nie chce evala. Z (jednym) evalem umiem sobie zrobić bo co to za trudność ;/ Tylko chce bez evala. Może da się to jakoś przez referencje zrobić?


--------------------
Go to the top of the page
+Quote Post
Kirtan Loor
post 26.06.2006, 09:53:08
Post #8





Grupa: Zarejestrowani
Postów: 44
Pomógł: 0
Dołączył: 22.10.2004
Skąd: Płock

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


Nie wiem jak by ci to mialo dzialac....


--------------------
A Chartreux et à Célestins, A Mendiants et à Dévotes,
A musards et claquepatins, A servants et filles mignottes
Portants surcots et justes cottes,A cuidereaux d'amour transis,
Chaussant sans méhaing fauves bottes, Je crie à toutes gens mercis.
Go to the top of the page
+Quote Post
bim2
post 26.06.2006, 10:00:12
Post #9





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


no, np przyłączanie tablic (jaka to była funkcja...) i wywołał to w referencji ;P. Tylko nie mam pomysłu jak. Może ktoś wpadnie ?


--------------------
Go to the top of the page
+Quote Post
siemakuba
post 26.06.2006, 10:08:22
Post #10





Grupa: Przyjaciele php.pl
Postów: 1 112
Pomógł: 20
Dołączył: 10.04.2005

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


hej, mam taką funkcję, która tłumaczy ścieżkę na tablicę:
  1. <?php
  2. ArrayGet('config.users.database.password', $tablica);
  3. // zwraca wartość z tablicy:
  4. $tablica['config']['users']['database']['password'];
  5. ?>

nie wiem czy to do końca to co potrzebujesz, ale nie wykorzystuje tam eval, więc w razie czego bez problemu sobie przerobisz według potrzeb. Nie mam dostępu do tego kodu teraz, wieczorem dopisze tu.

pozdr.
Go to the top of the page
+Quote Post
bim2
post 26.06.2006, 10:25:36
Post #11





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


Zobacze, w pewnym sensie o to chodzi. Bo wyciagam tabica:tablica1:tablica2 wiec moge zamiast kropek zmienic na : ;P Dzieki


--------------------
Go to the top of the page
+Quote Post
Kirtan Loor
post 26.06.2006, 12:42:13
Post #12





Grupa: Zarejestrowani
Postów: 44
Pomógł: 0
Dołączył: 22.10.2004
Skąd: Płock

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


Cytat(siemakuba @ 26.06.2006, 09:08 ) *
hej, mam taką funkcję, która tłumaczy ścieżkę na tablicę:
  1. <?php
  2. ArrayGet('config.users.database.password', $tablica);
  3. // zwraca wartość z tablicy:
  4. $tablica['config']['users']['database']['password'];
  5. ?>

nie wiem czy to do końca to co potrzebujesz, ale nie wykorzystuje tam eval, więc w razie czego bez problemu sobie przerobisz według potrzeb. Nie mam dostępu do tego kodu teraz, wieczorem dopisze tu.

pozdr.


Hmm, czy to nie jest funkcja Javy?


--------------------
A Chartreux et à Célestins, A Mendiants et à Dévotes,
A musards et claquepatins, A servants et filles mignottes
Portants surcots et justes cottes,A cuidereaux d'amour transis,
Chaussant sans méhaing fauves bottes, Je crie à toutes gens mercis.
Go to the top of the page
+Quote Post
siemakuba
post 26.06.2006, 22:02:49
Post #13





Grupa: Przyjaciele php.pl
Postów: 1 112
Pomógł: 20
Dołączył: 10.04.2005

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


oto obiecana funkcja:
  1. <?php
  2. function &ArrayGet(&$array, $path)
  3. {  
  4. $retval = null;
  5. $path  = explode('.', $path);
  6.  
  7. foreach ($path as $track)
  8. {
  9. if (!empty($retval)) 
  10. {  
  11. if (isset($retval[$track]))
  12. {  $retval =& $retval[$track];
  13. }
  14. else
  15. {  
  16. $retval = null;
  17. break;
  18. }
  19. }
  20. else
  21. {  $retval =& $array[$track];
  22. }
  23. }
  24. return $retval;
  25. }
  26. ?>

przykład:
  1. <?php
  2. $arr['test']['value']['foo'][] = 'bar1';
  3. $arr['test']['value']['foo'][] = 'bar2';
  4. $arr['test']['value']['foo'][] = 'bar3';
  5. $arr['test']['value']['foo'][] = 'bar4';
  6.  
  7. $test_value = ArrayGet($arr, 'test.value');
  8. print_r($test_value);
  9. ?>

wynik:
Kod
Array
(
    [foo] => Array
        (
            [0] => bar1
            [1] => bar2
            [2] => bar3
            [3] => bar4
        )

)

mam nadzieje że się przyda :)
Cytat
Hmm, czy to nie jest funkcja Javy?

@Kirtan Loor: hehe :) znam dwie Javy - Java wyspa jak wulkan gorąca i JavaScript :P
Notacja jest jak faktycznie jak w JavaScript, ale funkcja jest zdecydowanie php.

pozdr.
Go to the top of the page
+Quote Post
bim2
post 27.06.2006, 09:04:53
Post #14





Grupa: Zarejestrowani
Postów: 1 873
Pomógł: 152
Dołączył: 9.04.2006
Skąd: Berlin

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


Wilkie dzieki ;P. Dodałem to do swojego prega i dziala:
  1. <?
  2. function &ArrayGet(&$array, $path)
  3. {  
  4. $retval = null;
  5. $path  = explode(':', $path);
  6.  
  7. foreach ($path as $track)
  8. {
  9. if (!empty($retval)) 
  10. {  
  11. if (isset($retval[$track]))
  12. {  $retval =& $retval[$track];
  13. }
  14. else
  15. {  
  16. $retval = null;
  17. break;
  18. }
  19. }
  20. else
  21. {  $retval =& $array[$track];
  22. }
  23. }
  24.  
  25. return $retval;
  26. }
  27.  
  28. $inf[2][5]='wysmienicie';
  29. $infos[2][5][8][4]='działa';
  30. function zmien($match)
  31. {
  32. global $$match[1];
  33.  
  34. return ArrayGet($$match[1], $match[2]);
  35. }
  36. $test='To {infos:2:5:8:4} {inf:2:5}';
  37. $test=preg_replace_callback("/{([A-Za-z_]*):([A-Za-z0-9:]*)}/", 'zmien', $test);
  38.  
  39. echo $test;
  40. ?>


--------------------
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: 18.07.2025 - 01:34