首页 > Other > PHP 限制HTML内容中的图片必须是本站的

PHP 限制HTML内容中的图片必须是本站的

当用户发帖或者写博客的时候,使用的所见即所得的编辑器允许用户插入图片,服务器接收到这个内容后对 html 进行检查,只允许是站内的图片,否则不予显示

php

<?php
$dom = new DOMDocument;
$dom->loadHTML(file_get_contents(‘input.html’));
$xpath = new DOMXpath($dom);
$img = $xpath->query(‘//img’);
foreach($img as $i) {
$url = parse_url($i->getAttribute(‘src’));
if(isset($url[‘host’]) && in_array($url[‘host’], array(‘yourdomain.com’, ‘www.yourdomain.com’)) == false) {
// show an error
//

分类:Other
  1. 还没有评论。
  1. No trackbacks yet.

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: