It is necessary through php in the img tag to pull the src attribute, for example:

<img class="alignnone size-medium wp-image-63" src="/wp-content/uploads/2016/09/doorhan7-300x155.jpg" alt="doorhan7" width="300" height="155" /> 

from here should get /wp-content/uploads/2016/09/doorhan7-300x155.jpg

    1 answer 1

    You can do the following:

     <?php $text = '<img class="alignnone size-medium wp-image-63" '. 'src="/wp-content/uploads/2016/09/doorhan7-300x155.jpg" '. 'alt="doorhan7" width="300" height="155" />'; $pattern = '/<img[^>]+src=["\']([^\'"]+)["\']/'; if(preg_match($pattern, $text, $out)) echo $out[1]; 
    • And for <img class="alignnone size-medium wp-image-63" src="/wp-content/uploads/2016/09/door'han7-300x155.jpg" alt="doorhan7" width="300" height="155" /> regular returns /wp-content/uploads/2016/09/door 2016/09 /wp-content/uploads/2016/09/door : b - Visman
    • If you know in advance that all strings are wrapped with double quotes, you can remove single quotes from a regular expression and then this case will be processed. The problem is that providing more and more special cases we complicate a regular expression, this is also not very good (especially if the case is not realized, and the regular expression needs to be supported further). - cheops