hackerman Posted June 24, 2008 Report Share Posted June 24, 2008 (edited) Es īsti nemāku uzrakstīt strādājošu kodu ar preg_match_all. Kods: $file = file_get_contents('http://lapa.lv/tet.txt'); $k = preg_match_all('@(<div class="thumbpart">)(.*)(</div>)@', $file, $matches); echo $k; Kāpēc kods neizpildās, ja man faila tet.txt saturs ir šāds: <div class="thumbpart"> test4</div> <div class="thumbpart"> test2</div> <div class="thumbpart"> test3</div> Bet, ja kods ir bez nekādām atstarpēm, piemēram <div class="thumbpart">test4</div>, tad kods izpildās. Edited June 24, 2008 by hackerman Link to comment Share on other sites More sharing options...
bubu Posted June 24, 2008 Report Share Posted June 24, 2008 Droši vien tāpēc, ka pēc noklusējuma . nenomatcho \n simbolus (pārnesi uz jaunu rindu): . match any character except newline (by default) Lai to apietu, eksiste speciāls modifiers: s (PCRE_DOTALL) If this modifier is set, a dot metacharacter in the pattern matches all characters, including newlines. Without it, newlines are excluded. RTFM īsāk sakot ;) Link to comment Share on other sites More sharing options...
hackerman Posted June 24, 2008 Author Report Share Posted June 24, 2008 (edited) Paldies, sataisīju. Viss strādā. Edit: Jauna problēma :) $k = preg_match_all('@(<div class="thumbpart"><img src=")(.*)(" id=")(.*)(" /></div>)@msU', $file, $matches); īsti nestrādā, kā vajadzētu. Es speciāli iekš tās match funkcijas esmu iekļāvis to ID un SRC. Es gribu tikai tos, bet man velkās līdzi visādi alt un citi tādi atribūti, kuri man nav vajadzīgi. Edited June 24, 2008 by hackerman Link to comment Share on other sites More sharing options...
Recommended Posts