導航:首頁 > 凈水問答 > php過濾圖片函數

php過濾圖片函數

發布時間:2021-11-27 09:36:58

『壹』 PHP 過濾函數有哪些

①常用的安全函數:

mysql_real_escape_string()

addslashes()

②這些函數的作用:

mysql_real_escape_string()和addslashes()函數都是對數據中的
單引號、雙引號進行轉義!也就是防止sql注入!
但是mysql_real_escape_string()考慮了字元集,更加的安全一些!
經過查閱相關的資料,可以得出一個結論:當前的字元集是單位元組的話,這兩個函數作用相同,都可以起到轉義過濾的作用,但是,有誰會只是用單位元組呢?尤其是utf8越來越廣泛的被使用到!

③函數的用法:

在了解mysql_real_escape_string()和addslashes()這兩個函數的用法的時候,我們必須先了解另外兩個函數的含義!

get_magic_quotes_gpc()和get_magic_quotes_runtime(),我們來比較一下兩個函數的異同:

相同:
a、兩者都是用來獲取php.ini配置文件的配置情況的!當開啟的時候返回1,關閉的時候返回0!

b、當開啟的時候,都會對指定范圍內的數據進行轉義過濾!

『貳』 php 處理圖片的函數

提交的表單中,你直接在<src img='' width='' height=''>里設置就行了,下面給你貼一個水印代碼
<?php
$image="桔梗8.jpg";
$img=getimagesize($image);
switch($img[2]) {
case 1;
$im=@imagecreatefromgif($image); break;

case 2;
$im=@imagecreatefromjpeg($image); break;
case 3;
$im=@imagecreatefrompng($image); break;

}
$image2="0001.jpg";
$img2=getimagesize($image2);
switch ($img2[2]){
case 1;
$im2=@imagecreatefromgif($image2); break;
case 2;
$im2=@imagecreatefromjpeg($image2); break;
case 3;
$im2=@imagecreatefrompng($image2); break;

}
image($im,$im2,400,50,0,0,100,96);
$cl=imagecolorallocate($im,55,0,45);
$str=iconv("gbk","UTF-8","新年快樂!
QQ:41423439");
imagettftext($im,23,0,50,130,$cl,"jian.ttf",$str);
$new=imagecreatetruecolor(200,200);
imageresized($new,$im,0,0,0,0,200,200,$img[0],$img[1]);

header("Content-type:image/jpg");
imagejpeg($new,"哈哈.jpg");
?>

『叄』 PHP正則過濾文章中的圖片 如: <img src="das"> 我想把文章中得這些標簽都用正則去掉,該怎麼寫正則。

寫個正則表達式提花掉
$txt="你得到的文章內容";
$pattern='/<img\s+src=[\\\'| \\\"](.*?(?:[\.gif|\.jpg]))[\\\'|\\\"].*?[\/]?>/';
$str="用空白替換吧";
$txt=preg_replace($pattern,$str,$txt);

『肆』 php 文章需要過濾掉img標簽

PHP的preg_replace函數是 執行一個正則表達式的搜索和替換

語法

1:preg_replace (pattern ,replacement ,subject,limit,count )

參數

描述

pattern 正則表達式(字元串或字元串數組)

replacement 用於替換的字元串或字元串數組

subject 要進行搜索和替換的字元串或字元串數組。

limit 可選。每個模式在每個subject上進行替換的最大次數。默認是 -1(無限)。

cout 可選。完成的替換次數

示例:

<?php//把heigth高度屬性刪除,並添加width="100%"
$str='<div><p>12312321</p><imgsrc="xx.jpg"height="213"/><span>111</span><imgsrc="xz.jpg"/></div>';
$str=preg_replace("/height="[0-9]+?"/","",$str);
$str1=preg_replace("/src="(.+?)"/","src="$1"width="100%"",$str);
print_r($str1);
?>

『伍』 PHP 過濾HTML中除了img標簽外其它所有標簽,同時保留標簽內容,但<script>標簽內的內容都清除。

提供實例:
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
echo strip_tags($text);
echo "\n";
// 允許 <p> 和 <a>
echo strip_tags($text, '<p><a>');
?>
以上常式會輸出:版
Test paragraph. Other text
<p>Test paragraph.</p> <a href="#fragment">Other text</a>

具體做權法:
<?php
echo strip_tags($text, 'img');
?>

『陸』 php 圖象處理函數 imagestring 函數的運用

可以用imagettftext來生成,支持truetype字體

array imagettftext ( resource image, float size, float angle, int x, int y, int color, string fontfile, string text )

image
圖像資源。見 imagecreatetruecolor()。

size
字體大小。根據 GD 版本不同,應該以像素大小指定(GD1)或點大小(GD2)。

angle
角度製表示的角度,0 度為從左向右讀的文本。更高數值表示逆時針旋轉。例如 90 度表示從下向上讀的文本。

x
由 x,y 所表示的坐標定義了第一個字元的基本點(大概是字元的左下角)。這和 imagestring() 不同,其 x,y 定義了第一個字元的左上角。例如 "top left" 為 0, 0。

y
Y 坐標。它設定了字體基線的位置,不是字元的最底端。

color
顏色索引。使用負的顏色索引值具有關閉防鋸齒的效果。見 imagecolorallocate()。

fontfile
是想要使用的 TrueType 字體的路徑。

根據 PHP 所使用的 GD 庫的不同,當 fontfile 沒有以 / 開頭時則 .ttf 將被加到文件名之後並且會在庫定義字體路徑中嘗試搜索該文件名。

當使用的 GD 庫版本低於 2.0.18 時,一個空格字元 而不是分號將被用來作為不同字體文件的「路徑分隔符」。不小心使用了此特性將會導致一條警告信息:Warning: Could not find/open font。對受影響的版本來說唯一解決方案就是將字體移動到不包含空格的路徑中去。

很多情況下字體都放在腳本的同一個目錄下。下面的小技巧可以減輕包含的問題。 <?php
// Set the enviroment variable for GD
putenv('GDFONTPATH=' . realpath('.'));

// Name the font to be used (note the lack of the .ttf extension)
$font = 'SomeFont';
?>

text
文本字元串。

可以包含十進制數字化字元表示(形式為:€)來訪問字體中超過位置 127 的字元。UTF-8 編碼的字元串可以直接傳遞。

如果字元串中使用的某個字元不被字體支持,一個空心矩形將替換該字元。

imagettftext() 返回一個含有 8 個單元的數組表示了文本外框的四個角,順序為坐下角,右下角,右上角,左上角。這些點是相對於文本的而和角度無關,因此「左上角」指的是以水平方向看文字時其左上角。

例子 1. imagettftext() 例子

本例中的腳本將生成一個白色的 400x30 像素 PNG 圖像,其中有黑色(帶灰色陰影)Arial 字體寫的「Testing...」。

<?php
// Set the content-type
header("Content-type: image/png");

// Create the image
$im = imagecreatetruecolor(400, 30);

// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);

// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';

// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);

// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

『柒』 php中自定義函數過濾

這里是調用php中的filter_var函數,該函數的參數是這樣的,filter_var(variable, filter, options)
參數 描述
variable 必需。規定要過濾的變數。
filter 可選。規定要使用的過濾器的 ID。
options 規定包含標志/選項的數組。檢查每個過濾器可能的標志和選項。
1.options只是數組的一個key值,就是鍵值,它的value是$string執行完converSpace函數後返回值
2,要傳入第三個參數,第三個參數必須是數組哦

『捌』 php截取摘要時如何過濾圖片

php 字元截取與圖片過濾函數
本文章免費為各位朋友提供一款哦,如果你喜歡的話不防進來看看這款圖片過濾正則表達試
function msubstr($str, $start, $len) {
$tmpstr = "";
$strlen = $start + $len;
for($i = 0; $i < $strlen; $i++) {
if(ord(substr($str, $i, 1)) > 0xa0) {
$tmpstr .= substr($str, $i, 2);
$i++;
} else
$tmpstr .= substr($str, $i, 1);
}
return $tmpstr;
}

//過濾圖片
function img_empty($content){
$content=eregi_replace("<IMG ([a-zA-Z0-9~!& ?:"/._#=~&%]+)>","",$content);
return $content;
}

『玖』 php 過濾HTML格式但得保留圖片的正則表達式

花了點時間,試了N種終於搞定了..有點難度!
<?php
$str = '<div><span><table><tr><td>我ftyrtyrt<b>是</b>中<strong>國</strong>人<img src=images/logo.jpg></td></tr></table></span></div>';
preg_match('/(>[^<](.+)?\.jpg>)/', $str, $arr);
// print_r($arr); // 為什麼這會是亂碼?不解?
echo substr($arr[0], 1);
?>

『拾』 PHP 正則過濾圖片的代碼

$oldhtml = "<div><span><img src=\"11\" />111111<img src=\"33\" /><img src=\"22\" /></span></div>";
$pattern = "#<img[^復>]+>#";
$html = preg_replace ($pattern , "" , $oldhtml);
輸出的制結果就替換掉所有圖片了

閱讀全文

與php過濾圖片函數相關的資料

熱點內容
回奶帶胸罩起啥做用 瀏覽:818
熱水壺壺嘴水垢怎麼去除 瀏覽:410
廣東污水處理配套設備 瀏覽:805
煤礦企業污水處理廠運行新聞稿 瀏覽:990
ro反滲透如何計算產水量 瀏覽:865
鮁魚圈開發區污水處理廠二期 瀏覽:891
遼寧車站飲水機加盟利潤怎麼樣 瀏覽:271
鑄鐵壺去水垢 瀏覽:44
純水機廢水什麼時候產生 瀏覽:377
加油兩千空氣濾芯燈亮怎麼回事 瀏覽:606
三角牌凈水器一直響怎麼辦 瀏覽:868
樹脂粘接橋修復的缺點 瀏覽:744
自來水過濾器如何安裝 瀏覽:490
樹脂硅元素含量多少 瀏覽:305
教你自製污水過濾器簡易有效 瀏覽:672
污水池膜密封方案 瀏覽:53
巴中印刷污水處理什麼價格 瀏覽:253
純凈水反滲透膜哪裡便宜 瀏覽:184
凈化器凈化水速度慢怎麼解決 瀏覽:905
超濾精度數值 瀏覽:293