Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Wyrażenie regularne - błędne wyłapanie wartości
Elber
post 3.10.2014, 11:21:06
Post #1





Grupa: Zarejestrowani
Postów: 381
Pomógł: 12
Dołączył: 9.07.2007

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


witam,

mam ciąg

  1. $this->_headerText = Mage::helper('productstable')->__('Products Table').Mage::helper('productstable')->__('Add Products Table');


i chcę wyłapać tylko to co jest w __('')

gdy wykonuje

  1. preg_match_all("/__\('(.+)'\)?/", $file, $string);


skrypt zwraca mi

  1. Products Table'),Mage::helper('productstable')->__('Add Products Table


jeśli ciąg dam do nowej linii to jest ok, problem tylko z tym gdy jest w 1 linii.


--------------------
GG: 564555
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
luck
post 3.10.2014, 11:55:39
Post #2





Grupa: Zarejestrowani
Postów: 317
Pomógł: 58
Dołączył: 6.11.2005

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


Biorąc pod uwagę efekt, jaki chesz uzyskać, to po mojemu to masz znak zapytania w niewłaściwym miejscu. Spróbuj tak:
  1. /__\('(.+?)'\)/

Powinno być lepiej. Pozdrawiam.


--------------------
Go to the top of the page
+Quote Post
Elber
post 3.10.2014, 12:01:54
Post #3





Grupa: Zarejestrowani
Postów: 381
Pomógł: 12
Dołączył: 9.07.2007

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


Ok, działa a jeśli byłoby

$this->_headerText = Mage::helper('productstable')->__('Products Table').Mage::helper('productstable')->__("Add Products Table", $dsacsada);

jak wyłapać te Add Products Table ?


--------------------
GG: 564555
Go to the top of the page
+Quote Post
Turson
post 3.10.2014, 12:13:29
Post #4





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


Kolejne (.+?) w tym miejscu
Go to the top of the page
+Quote Post
Elber
post 3.10.2014, 12:14:55
Post #5





Grupa: Zarejestrowani
Postów: 381
Pomógł: 12
Dołączył: 9.07.2007

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


No właśnie nie bo teraz mamy 2 przypadki

1.
  1. __('Products Table')

2.

  1. __("Add Products Table", $dsacsada)


--------------------
GG: 564555
Go to the top of the page
+Quote Post
luck
post 3.10.2014, 12:34:39
Post #6





Grupa: Zarejestrowani
Postów: 317
Pomógł: 58
Dołączył: 6.11.2005

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


Chcemy gotowca? wink.gif
  1. __\(['"](.+?)['"].*?\)


--------------------
Go to the top of the page
+Quote Post
Elber
post 3.10.2014, 12:51:15
Post #7





Grupa: Zarejestrowani
Postów: 381
Pomógł: 12
Dołączył: 9.07.2007

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


Nie gotowca, sam cały czas próbuję ale nie wychodzi,

Na http://www.phpliveregex.com/ działa ladnie, jednak w php wyrzuca mi błąd

Warning: preg_match_all(): Unknown modifier '\'

  1. preg_match_all("__\(['\"](.+?)['\"].*?\)", $file, $string);


bo jak dam preg_match_all("__\(['"](.+?)['"].*?\)", $file, $string); to mam błąd zamkniętego "


--------------------
GG: 564555
Go to the top of the page
+Quote Post
Turson
post 3.10.2014, 12:53:29
Post #8





Grupa: Zarejestrowani
Postów: 4 291
Pomógł: 829
Dołączył: 14.02.2009
Skąd: łódź

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


  1. preg_match_all("#__\(['\"](.+?)['\"].*?\)#", $file, $string);
Go to the top of the page
+Quote Post
Elber
post 3.10.2014, 12:56:20
Post #9





Grupa: Zarejestrowani
Postów: 381
Pomógł: 12
Dołączył: 9.07.2007

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


Działa wyśmienicie smile.gif muszę poświęcić więcej czasu wyrażeniom regularnym bo cienko z nimi wink.gif Dziękuję za pomoc.


--------------------
GG: 564555
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 - 11:45