DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

PHP: Random String

08.20.2008
| 5529 views |
  • submit to reddit
        // Creating string with mt_rand() more random 
<?php
$str = ''; /* Future string */
$maxchar = 8; /* The maximum number of characters */
$chars = str_shuffle('abcdef1234567890');
$len = strlen($chars);
for ($i = 0; $i < $maxchar; $i++)
{
	$str .= $chars[mt_rand(0, $len-1)];
}
print $str;
?>
    

Comments

Snippets Manager replied on Thu, 2008/08/21 - 12:06pm

<?php if( $_POST['album'] ) { $album = trim($_POST['album']); $showall = trim($_POST['showall']); $tmp = fetchWebSource($album, $showall); $pattern = "/ $v ) { $img = str_replace("/thumbs/t","/", $v); echo '
'; //這段是直接輸出img,不過因為無名擋外部讀檔,所以還要再寫一個PHP專門讀取圖檔. } } function fetchWebSource($url, $showall=0) { $ch=curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_REFERER, "http://www.wretch.cc/"); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Accept-Language: en-GB,zh-tw;q=0.5")); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("UA-CPU: x86")); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Accept-Encoding: gzip, deflate")); curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Connection: Keep-Alive")); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; InfoPath.2; FDM; .NET CLR 1.1.4322)"); if( $showall ) curl_setopt($ch, CURLOPT_COOKIE, "showall=1; a_page=1; lang=zh-tw"); $result = curl_exec($ch); curl_close($ch); return $result; } ?> 是否要展現全部圖案