Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wyrażenia regularne
daris
post
Post #1





Grupa: Zarejestrowani
Postów: 78
Pomógł: 4
Dołączył: 7.01.2008

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


Jak zrobić tak aby w danym kodzie html za pomocą wyrażeń regularnych wyłapać wszystkie wystąpienia <input type=button value=cos_tam> i dodać do tablicy to cos_tam?

Np jak mam taki kod:
  1. <input type=button value=test><input type=button value=test3>

To chciałbym otrzymać coś takiego:
Kod
Array
(
    [0] => test
    [1] => test3
)


Udało mi się to zrobić narazie tylko takim wyrażeniem:
Kod
#\<input (.*)type=button(.*)value=test\>(.*)>#s

ale co mi po tym jak nie do końca działa tak jak powinno czyli może pasować np taki kod:
Kod
<input type=button>fds value=test dsfsdfs<input type=button value=test>


Jak to zawęzić?

Ten post edytował daris 22.01.2008, 15:10:05
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nowotny
post
Post #2





Grupa: Zarejestrowani
Postów: 875
Pomógł: 122
Dołączył: 2.02.2008

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


Aż takie proste to to nie jest... (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)
  1. <?php
  2. $string='asdfsd fa sdf asdf <!-- pokaz element 5 --> asdf asdf <!-- element --> asdf <!-- element --> asdf sdf <!-- pokaz element 5 --> asf asd f as';
  3.  
  4. echo preg_replace_callback('#<!--.+element ([^ ]+|)[ ]?-->#U','clbk',$string);
  5.  
  6. function clbk($array){
  7. if($array[1]=='') return drawElement();
  8. else return drawElement($array[1]);
  9. }
  10. ?>


Ten post edytował nowotny 18.02.2008, 15:58:50
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 7.10.2025 - 18:07