PHP如何隨機生成中文段落-測試網(wǎng)站內(nèi)容時使用-創(chuàng)新互聯(lián)

本篇內(nèi)容介紹了“PHP如何隨機生成中文段落-測試網(wǎng)站內(nèi)容時使用”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

在青神等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作按需策劃,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站制作,全網(wǎng)整合營銷推廣,外貿(mào)營銷網(wǎng)站建設(shè),青神網(wǎng)站建設(shè)費用合理。

在創(chuàng)建網(wǎng)站的時候,很多時候都需要輸入一些中文的段落來填充頁面,大多數(shù)會是找一些新聞之類的來復(fù)制粘貼。

以下代碼是利用php來隨機生成一些中文段落,以便用來測試。

GBK版:

<?php
header('Content-type:text/html;charset=gbk');

function createWords($words = 128)
{
  $seperate = array(",","。","!","?",";");
  $strings = '';
  for ($i=0; $i<$words; $i++)
  {
    $strings .= chr(rand(0xB0,0xD6)).chr(rand(0xA1,0xFE));
    if (fmod($i, 18) > rand(10, 20))
    {
      $strings .= $seperate[rand(0, 4)];
    }
  }
  return $strings;
}

$paras = rand(1, 10);

$strings = '';

for($i=0; $i<$paras; $i++)
{
  $strings .= '&nbsp;&nbsp;&nbsp;&nbsp;'.createWords(rand(100, 500)).'<br />';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/tupian/20230522/xhtml1-transitional.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=gbk" />
  <title>隨機生成中文段落</title>
  <style type="text/css">
    body{
      width: 960px;
      margin: 0 auto;
    }
    h2 {
      text-align: center;
    }
  </style>
</head>

<body>
  <h2>刷新頁面可得到不同結(jié)果</h2>
  <div><?php echo $strings;?></div>
</body>

UTF8版:

<?php
function createWords($words = 128)
{
  $seperate = array(",", "。", "!", "?", ";");
  $strings = '';
  for ($i=0; $i<128; $i++)
  {
    $strings .= iconv('utf-16', 'utf-8', chr(rand(0x00, 0xFF)).chr(rand(0x4E, 0x99)));
    if (fmod($i, 18) > rand(10, 20))
    {
      $strings .= $seperate[rand(0, 4)];
    }
  }
  return $strings;
}

$paras = rand(1, 10);
$strings = '';

for($i=0; $i<$paras; $i++)
{
  $strings .= '&nbsp;&nbsp;&nbsp;&nbsp;'.createWords(rand(100, 500)).'<br />';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/tupian/20230522/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>測試</title>
  <style type="text/css">
    body{
      width: 960px;
      margin: 0 auto;
    }
    h2 {
      text-align: center;
    }
  </style>
</head>
<body>
  <h2>刷新頁面可得到不同結(jié)果</h2>
  <div><?php echo $strings;?></div>
</body>
</html>

“PHP如何隨機生成中文段落-測試網(wǎng)站內(nèi)容時使用”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

當(dāng)前題目:PHP如何隨機生成中文段落-測試網(wǎng)站內(nèi)容時使用-創(chuàng)新互聯(lián)
網(wǎng)站鏈接:http://www.muchs.cn/article24/dhosje.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗、面包屑導(dǎo)航、云服務(wù)器、微信小程序、網(wǎng)站設(shè)計、響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都做網(wǎng)站