ebw Posted October 26, 2006 Report Share Posted October 26, 2006 censhos te tikt skaidriibaa ar regular expressions. bet gluzhi labi nesanaak :( censhos atlasiit no html koda gabalus ar noteiktiem tagiem, piem. <img ...> aptuveni taa sanaaca ka vinjsh vispaar atrod rindu ar img tagiem: preg_match("/<img(.+)>/uis", $line) kaa vareetu ar regexp izdabuut shii <img> taga src="..." esoshos datus? paldies! Link to comment Share on other sites More sharing options...
Delfins Posted October 26, 2006 Report Share Posted October 26, 2006 Nu tā arī raksti <img(.*)src="([^"]+)"(.*)> Link to comment Share on other sites More sharing options...
Orion7 Posted October 30, 2006 Report Share Posted October 30, 2006 (edited) Jā nu var jau to darīt ar preg_match utml, bet es, piemēram, esmu uztaisījis skriptu, ar ko lejuplādēt ne pārāk sarežģītas weblapas, tad to webadrešu izvilkšanu esmu iztaisījis «vienkārši» (viss ģeniālais kā zināms ir vienkāršs. :) ): <?php $b = 'http://www.somesite.com/abc/dfg'; $u = 'http://www.somesite.com'; // lapas base un site, ko dabūnam no url. $check = Array('href=', 'src=', 'url(', 'background='); // atlasām rindas kuras analizēt $lines = explode(">",$in); // iekš $in ir html kods. foreach($lines as $line) { $line=trim($line); $line=str_replace(' =','=',$line); $line=str_replace('= ','=',$line); // unificējam $a=0; foreach($check as $ch) if(stripos($line,$ch)) { $a=1; break; } if($a==0) continue; if(strpos($line,'ftp://')) continue; $h = ''; // ftp neanalizējam if(strpos($line,'http://')) { $h = substr(strstr($line,'http://'),0); } else if(stripos($line,'src=')) { $h = substr(stristr($line,'src='),4); if(strpos(' '.$h,'"./')) $h = str_replace('"./','"/',$h); if($h[0]=='"'||$h[0]=="'") $h=substr($h,1); if($h[0]=='/') $h=$u.$h; else $h=$b.'/'.$h; } else if(stripos($line,'href=')) { $h = substr(stristr($line,'href='),5); if(strpos(' '.$h,'"./')) $h = str_replace('"./','"/',$h); if($h[0]=='"'||$h[0]=="'") $h=substr($h,1); if($h[0]=='/') $h=$u.$h; else $h=$b.'/'.$h; } else if(stripos($line,'url(')) { $h = substr(stristr($line,'url('),4); if(strpos(' '.$h,'"./')) $h = str_replace('"./','"/',$h); if($h[0]=='"'||$h[0]=="'") $h=substr($h,1); if($h[0]=='/') $h=$u.$h; else $h=$b.'/'.$h; } // nogriežam nevajadzīgo if(strpos($h,' ')) $h=substr($h,0,strpos($h,' ')); if(strpos($h,">")) $h=substr($h,0,strpos($h,">")); if(strpos($h,')')) $h=substr($h,0,strpos($h,')')); if(strpos($h,'"')) $h=substr($h,0,strpos($h,'"')); if(strpos($h,"'")) $h=substr($h,0,strpos($h,"'")); // te dabūnam sourci no $h ... } ?> Edited October 30, 2006 by Orion7 Link to comment Share on other sites More sharing options...
Recommended Posts