For example, you need to find the url of the picture here (this is part of the large text where the desired picture is located)

<div class="doc-banner-icon"><img src="https://lh3.ggpht.com/0RHA6wgcdzFtGxINiNohDV9ppDaVsz_1z-KXI8GKO-kFRu6fs5T4nXlz1kDaGLcohQ=w124"></div> 

What is the general principle of setting templates?

    3 answers 3

    I would search for the beginning " <img " further until it closes " > " I searched for " src=\"(что-то кроме \") , "

    Did not check, but something like this:

     #<img[^>]+src="([^"]+)"# 

    Upd . Checked on that feed, it works (screenshot) :)

       preg_match_all('/<img[^>]*?src="([^"]*)"[^>]*>/i', $HTMLstr, $matches); 

      In $ matches [1] there will be an array with all URLs. I just did this task for myself.

      • Something I get is $ matches [1] - an array with dimension 0 - I ’m living
      • And the variable $ HTMLstr what is it like? Give a link to pastebin, for example. - Zhukov Roman
      • I tried to display the value of this line. out: Moved Temporarily The document has moved here. - I LIVE
      • Here and the error in it was =) - I Zhuju

      Try this:

       preg_match_all('/src=["](https:\/\/.*?[^"]+)/i', $str, $matches); 
      • $ matches [0] [$ i] and $ matches [1] [$ i] do not give anything - I LIVE
      • @ Yevhen Formanyuk, So you did not finish saying something. See an example in action . - Deonis