SnakeLV Posted November 23, 2008 Report Share Posted November 23, 2008 Mēgināju atrast skriptu, bet nesanāca. Tātad: Ir, piemēram, html kods. Un kaut kur, starp to ir img. Un tagad es taisu izvēlni/bloku un vēlos, lai tur parādās tas attēls, samazināts, apm, kā thumbnail, un zem tā teksts. Ehh.. nezinu, grūti izskaidrot. Nu man vajadzētu PHP kodu, kurš no dotā HTML koda atrastu IMG kodu. Link to comment Share on other sites More sharing options...
bubu Posted November 23, 2008 Report Share Posted November 23, 2008 To var ar regulāro izteiksmi: $htmls = '..foo.. <img src="blah.png"/> ..bar..'; if (preg_match('#<img src="[^"]+"/>#', $htmls, $m)) { echo $m[0]; } else { echo "nesatur bildi!"; }; Attiecīgi, ja tev tur var būt papildus class, id vai citi atribūti bildei, tad pielabo regulāro izteiksmi. Link to comment Share on other sites More sharing options...
SnakeLV Posted November 23, 2008 Author Report Share Posted November 23, 2008 (edited) Paldies :) eem. a var kaut kā izņemt nevis visu tagdu, bet tikai URL? Edited November 23, 2008 by SnakeLV Link to comment Share on other sites More sharing options...
bubu Posted November 23, 2008 Report Share Posted November 23, 2008 Protams, var. Nomaini regexpu uz '#<img src="([^"]+)"/>#' un pie echo izvadi $m[1] Link to comment Share on other sites More sharing options...
Ghenis Posted November 24, 2008 Report Share Posted November 24, 2008 foreach(simplexml_load_string($html, 'simpleXMLElement', LIBXML_NOWARNING)->xpath('//img') AS $img){ echo $img->attributes()->src; } Link to comment Share on other sites More sharing options...
bubu Posted November 24, 2008 Report Share Posted November 24, 2008 Kopš kuriem laikiem HTML's parsējas kā XML? Link to comment Share on other sites More sharing options...
Recommended Posts