Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] Przekazywanie zmiennych przez preg_replace szwankuje
Ziels
post 23.10.2006, 19:15:14
Post #1





Grupa: Zarejestrowani
Postów: 235
Pomógł: 2
Dołączył: 30.06.2006

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


Witam,

taki kod:
  1. <?php
  2. function row_replace($arg){
  3.  
  4. $test = 1;
  5. if($arg == 'left'){
  6. $test = 'działa';
  7. return $test;
  8. }else{
  9. return $arg;
  10. }
  11. }
  12. $zmienna = "[table align='left']ppp[/table]";
  13. $bb2html = preg_replace("#[table align='(.*?)']ppp[/table]#si", row_replace( "1" ), $zmienna);  
  14. echo $bb2html;
  15. ?>

Zwraca 'left' zamiast 'działa' mimo że argument $arg jest równy 'left'. Czy wie ktoś może dlaczego tak się dzieje?

Ten post edytował Ziels 23.10.2006, 19:27:14
Go to the top of the page
+Quote Post
piotrekkr
post 23.10.2006, 21:02:13
Post #2





Grupa: Zarejestrowani
Postów: 386
Pomógł: 25
Dołączył: 28.09.2005

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


arg jest rowny stringowi "\\1" a nie left;
zrob sobie takie cos :
  1. <?php
  2. function row_replace($arg){
  3. echo $arg;
  4. $test = 1;
  5. if($arg == 'left'){
  6. $test = 'działa';
  7. return $test;
  8. }else{
  9. return $arg;
  10. }
  11. }
  12. ?>
wtedy zobaczysz ze tak faktycznie jest

poza tym masz zly wzorzec.

Ten post edytował piotrekkr 23.10.2006, 21:48:21
Go to the top of the page
+Quote Post
Ziels
post 24.10.2006, 06:16:15
Post #3





Grupa: Zarejestrowani
Postów: 235
Pomógł: 2
Dołączył: 30.06.2006

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


Tego bym się nie spodziewał, masz racje winksmiley.jpg

Fixed!
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: 19.07.2025 - 19:33