Php 我有一篇来自db的文章,其中包含图像标签,我需要一个正则表达式来抓取图像并将其放入锚定标签中 前一段文字后一段文字

Php 我有一篇来自db的文章,其中包含图像标签,我需要一个正则表达式来抓取图像并将其放入锚定标签中 前一段文字后一段文字,php,Php,假设我在db的一些文本中有这样的包装。我需要将其更改为: Some text before <img style="float: left;" src="../images/265218_imgthw.jpg" alt="" width="81" height="88"> some text after 前一段文字后一段文字 请帮忙。 我试着用带explode的img标签来破解代码。它工作正常,但需要使用regEx减少代码。我就是这样做的: Some text before &l

假设我在db的一些文本中有这样的包装。我需要将其更改为:

Some text before <img style="float: left;" src="../images/265218_imgthw.jpg" alt="" width="81" height="88"> some text after
前一段文字后一段文字
请帮忙。
我试着用带explode的img标签来破解代码。它工作正常,但需要使用regEx减少代码。我就是这样做的:

Some text before <a href='../images/265218_imgthw.jpg'><img style="float: left;"     src="../images/265218_imgthw.jpg" alt="" width="81" height="88"></a> some text after
$string=“您可以使用一个名为$t的变量来完成此操作

$string = "<img";
$explored = explode($string,$desc);
$desc = "";
foreach ($explored as $key => $value) {
static $counter = 0; 
if(strpos($explored[$key], '/>')){
$desc .= "<a href='".$path.$image[$counter]."' class='lightview'><img".$explored[$key];
$counter++;
} else $desc .= $explored[$key]."<a href='".$path.$image[$key]."' class='lightview'><img";
                        }


$string = "/>";
                        $explored = explode($string,$desc);
                        $desc = "";
                        foreach ($explored as $key => $value) {
                                if(strpos($explored[$key], '<img'))
                                {
                                    $desc .= $explored[$key]."/></a>";
                                }
                                else $desc .= $explored[$key];

                            } 
/'$t'是要用锚点包装的元素
$tempHtml=str_get_html('.$t->outertext'.');
$link=$tempHtml->find('a',0);
//“$src”是链接的url
$link->href=$image['src'];

我尝试使用It's 2013来破解代码。请使用HTML解析器。
// '$t' is the element to be wrapped with anchor
$tempHtml = str_get_html('<a>' . $t->outertext . '</a>');
$link = $tempHtml->find('a', 0);
// '$src' is the url of the link
$link->href = $image['src'];