Skip to content

Commit

Permalink
兼容某些极其特殊的img匹配
Browse files Browse the repository at this point in the history
Signed-off-by: friend-nicen <[email protected]>
  • Loading branch information
friend-nicen authored and gitee-org committed Nov 19, 2024
1 parent 8df6cca commit 78be88e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions admin/when-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,22 @@ function nicen_make_when_save_post( $post_id, $flag = true ) {
return;
}

$post->post_content = str_replace( '></img>', "/>", $post->post_content );

//匹配所有图片
preg_match_all( '/<img(?:.*?)src="(.*?)"(?:.*?)\/?>/', $post->post_content, $match );
preg_match_all( '/<img(?:.*?)src="(.*?)"(?:.*?)\/?>/', , $post->post_content, $match );


/*如果没有图片*/
if ( empty( $match ) ) {
return;
if ( empty( $match[1] ) ) {
/*匹配单引号规则*/
preg_match_all( "/<img(?:.*?)src='(.*?)'(?:.*?)\/?>/", , $post->post_content, $match );
/*如果没有图片*/
if ( empty( $match[1] ) ) {
return;
}
}


$images = array_unique( $match[1] ); //去重
$site_url = site_url(); //站点url

Expand Down

0 comments on commit 78be88e

Please sign in to comment.