Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将图像类复制到Wordpress中的包装div容器_Php_Regex_Wordpress - Fatal编程技术网

Php 将图像类复制到Wordpress中的包装div容器

Php 将图像类复制到Wordpress中的包装div容器,php,regex,wordpress,Php,Regex,Wordpress,我想在Wordpress中用一个div容器包装一个图像 这就是我所拥有的: <div class="image-container"> <img class="alignleft size-full wp-image-24" src="http://example.com/wp-content/uploads/header01.jpg" alt="" width="512" height="512" /> </div> 但是如何在容器中获取类呢 谢

我想在Wordpress中用一个div容器包装一个图像

这就是我所拥有的:

<div class="image-container">

   <img class="alignleft size-full wp-image-24" src="http://example.com/wp-content/uploads/header01.jpg" alt="" width="512" height="512" />

</div>
但是如何在容器中获取类呢

谢谢你的帮助。

我解决了这个问题

function wrap_my_div($html, $id, $alt, $title, $align, $size){
    preg_match('/class="(.*)?"/', $html, $alignment);
    $html = preg_replace('/class="(.*)?"/', '', $html);
    $html = '<div class="image-container '. $alignment[1] .'">' . $html . '</div>';
    return $html;
}
add_filter('get_image_tag', 'wrap_my_div', 10, 4);
function wrap\u my\u div($html、$id、$alt、$title、$align、$size){
preg_match('/class=“(*)”/,$html,$alignment);
$html=preg_replace('/class=“(.*)”/,'','$html);
$html='.$html'.';
返回$html;
}
添加过滤器('get_image_tag','wrap_my_div',10,4);
我得看看正则表达式

add_filter('get_image_tag_class', '__return_empty_string');
function wrap_my_div($html, $id, $alt, $title, $align, $size){
    preg_match('/class="(.*)?"/', $html, $alignment);
    $html = preg_replace('/class="(.*)?"/', '', $html);
    $html = '<div class="image-container '. $alignment[1] .'">' . $html . '</div>';
    return $html;
}
add_filter('get_image_tag', 'wrap_my_div', 10, 4);