Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Preg_match problem
evolucja
post
Post #1





Grupa: Zarejestrowani
Postów: 362
Pomógł: 27
Dołączył: 14.09.2009

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


Chcę z HTMLa wyciągnąć value z inputa liczba_dodatnia. Fragment strony:
  1. class="img"><input type="hidden" name="liczba_dodatnia" value="4"><button type="submit"><span>

próbuję tak:
  1. preg_match( "@class=\"img\"><input type=\"hidden\" name=\"liczba_dodatnia\" value=\"(.*)\"><button type=\"submit\"><span>@si", $strona, $wyniki );

ale nie wychodzi... W czym jest problem?


--------------------
zmoderowano - waga i rozmiar
Go to the top of the page
+Quote Post
Fifi209
post
Post #2





Grupa: Zarejestrowani
Postów: 4 655
Pomógł: 556
Dołączył: 17.03.2009
Skąd: Katowice

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


  1. <?php
  2.  
  3. $string = 'class="img"><input type="hidden" name="liczba_dodatnia" value="4"><button type="submit"><span>';
  4.  
  5. $reg = '#class="img"><input type="hidden" name="liczba_dodatnia" value="([0-9]+)"><button type="submit"><span>#i';
  6.  
  7. preg_match($reg, $string, $match);
  8.  
  9. echo $match[1];
  10.  
  11. // Druga metoda
  12.  
  13. $val = substr($string, strpos($string, 'liczba_dodatnia" value="')+24, 1);
  14.  
  15. echo '<br/>'.$val;
  16.  
  17. ?>


--------------------
Zainteresowania: C#, PHP, JS, SQL, AJAX, XML, C dla AVR
Chętnie pomogę, lecz zanim napiszesz: Wujek Google , Manual PHP
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 Aktualny czas: 20.08.2025 - 12:59