• Source
    1. <?php
    2. $content = <<<'STR'
    3. <img class="leftimg"
    4. src="https://example.ru/img/shema/2016-05-20%2013-58-37.jpg"
    5. alt="Забор из профнастила" width="550" height="309" />
    6. STR;
    7.  
    8. $content = preg_replace('!<img(.*?)src(.*?)alt="(.*?)" width(.*?)height(.*?)\s\/>!si',
    9. '<span itemscope itemtype="https://schema.org/ImageObject">
    10. <span itemprop="name" style="display:none;">\\3</span>
    11. <span itemprop="author" style="display:none;">Author</span>
    12. <img itemprop="url contentUrl" \\1 src\\2 alt="\\3" title="\\3" width\\4 height\\5 />
    13. <meta itemprop="width" content\\4>
    14. <meta itemprop="height" content\\5></span>',$content);
    15.  
    16. echo $content;