目前共有11篇帖子。 內容轉換:不轉換▼
 
點擊 回復
779 10
【方法】解決gettext國際化導致Dreamweaver設計視圖中只顯示PHP代碼標記的問題
一派護法 十九級
1樓 發表于:2015-11-16 23:03
最終效果:
一派護法 十九級
2樓 發表于:2015-11-16 23:03
一派護法 十九級
3樓 發表于:2015-11-16 23:04
【PHP文件的代碼】
<?php
// 随机生成一个标题
function randstr() {
    $str = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM789456123';
    $len = strlen($str);
    $gen = '';
    for ($i = 0; $i < 50; $i++) {
        $gen .= $str{rand(0, $len - 1)};
    }
    return $gen;
}

// 为了节约时间,创建了一个______()函数来模拟gettext的_()函数的功能
function ______($str) {
    $array = array();
    $array['gettext Test'] = 'gettext测试页';
    $array['If you put gettext blocks here, there will be no effect on Dreamweaver\'s design view.'] = '如果你在这里放置调用gettext函数的PHP语句块,不会影响到Dreamweaver设计视图的显示';
    $array['This is Mary\'s name.'] = '这是玛丽的名字';
    $array['Don\'t you know this problem?'] = '难道你不知道这个问题吗?';
    $array['Title of Table'] = '表格标题';
    $array['Post ID'] = '编号';
    $array['Post Title'] = '标题';
    $array['Time Created'] = '创建时间';
    $array['There are %d posts.'] = '有%d個帖子。';
    if (isset($array[$str])) {
        return $array[$str];
    } else {
        return $str;
    }
}

// 下面的函数专门用来处理参数替换问题
$postsNum = 742;
function strCenter($translatedStr, $caseID) {
    switch ($caseID) {
    case 1:
        global $postsNum; // 调用函数外的变量
        return sprintf($translatedStr, $postsNum);
    default:
        return $translatedStr;
    }
}

function fetchText($result) {
    return strCenter(______($result[2]), (int)$result[1]);
}

date_default_timezone_set('PRC');
ob_start();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{*gettext Test}</title>
<style type="text/css">
body,td,th {
    font-family: Arial;
    font-size: 12px;
}
</style>
<script>
function a() {
    var a = "{{*Avoid losing brackets}}"; // 如果{}被误替换掉了的话,可以采用双写的方法解决
    var a2 = "{" + "*Avoid losing brackets}";
    var b = "<?=______('If you put gettext blocks here, there will be no effect on Dreamweaver\'s design view.')?>";
    if (a == b) {
        a = "48a";
        b = "3";
    } else {
       
    }
}
</script>
</head>

<body>
<article>
  <h2>{*This is Mary's name.}</h2>
  <p>{*Don't you know this problem?}<br>
    {1*There are %d posts.}
  </p>
</article>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tbody>
    <tr>
      <th colspan="3" align="center" scope="col"><h1>{*Title of Table}</h1></th>
    </tr>
    <tr>
      <td width="70" height="21" align="center" bgcolor="#EEEEEE">{*Post ID}</td>
      <td height="21" align="left" bgcolor="#EEEEEE">{*Post Title}</td>
      <td width="150" height="21" align="center" bgcolor="#EEEEEE">{*Time Created}</td>
    </tr>
<?php
for ($i = 0; $i < 50; $i++):
    $bgColor = (($i % 2) ? '#EEEEEE' : '#FFFFFF');
?>
    <tr bgcolor="<?=$bgColor?>">
      <td width="70" height="28" align="center"><?=$i+1?></td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=<?=$i+1?>"><?=htmlspecialchars(randstr())?></a></td>
      <td width="150" height="28" align="center"><?=date('Y-n-j H:i', rand(time() - 999999, time()))?></td>
    </tr>
<?php endfor; ?>
  </tbody>
</table>
</body>
</html>
<?php
$content = ob_get_clean();
$reg = '/\{(\d+)?\*([\w\s\'\?\.%]+)\}/'; //方括号内为{}中允许出现的字符列表,建议最好不要包括换行符\n,以免影响css和js代码
$content = preg_replace_callback($reg, 'fetchText', $content);
echo $content;
?>
一派護法 十九級
4樓 發表于:2015-11-16 23:06
2樓所示的截圖中的網頁不小心被放大了。
這是Firefox瀏覽器下100%查看網頁的效果:
一派護法 十九級
5樓 發表于:2015-11-16 23:06
【生成的HTML源文件】
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>gettext测试页</title>
<style type="text/css">
body,td,th {
    font-family: Arial;
    font-size: 12px;
}
</style>
<script>
function a() {
    var a = "{Avoid losing brackets}"; // 如果{}被误替换掉了的话,可以采用双写的方法解决
    var a2 = "{" + "*Avoid losing brackets}";
    var b = "如果你在这里放置调用gettext函数的PHP语句块,不会影响到Dreamweaver设计视图的显示";
    if (a == b) {
        a = "48a";
        b = "3";
    } else {
       
    }
}
</script>
</head>

<body>
<article>
  <h2>这是玛丽的名字</h2>
  <p>难道你不知道这个问题吗?<br>
    有742個帖子。
  </p>
</article>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tbody>
    <tr>
      <th colspan="3" align="center" scope="col"><h1>表格标题</h1></th>
    </tr>
    <tr>
      <td width="70" height="21" align="center" bgcolor="#EEEEEE">编号</td>
      <td height="21" align="left" bgcolor="#EEEEEE">标题</td>
      <td width="150" height="21" align="center" bgcolor="#EEEEEE">创建时间</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">1</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=1">WoxhRh2A4mriKhzacM1PVCKJUaVvYP56dolgAmHDoTh1VqZIew</a></td>
      <td width="150" height="28" align="center">2015-11-9 15:53</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">2</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=2">h7o7mJQm9UUCqMTpSP1heg2lpZpelSPFlC78YLy5CQ7YWch7cW</a></td>
      <td width="150" height="28" align="center">2015-11-15 11:25</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">3</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=3">KNdBhZPGdQrYBLP2X3FikrdIihLvEWsae3rwrJlIh5vNNUjWUN</a></td>
      <td width="150" height="28" align="center">2015-11-10 10:29</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">4</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=4">YIJ7DAW3756BNgYCSZw8BaBOTZJNlarulGKvt1qiZjBl8zQbPl</a></td>
      <td width="150" height="28" align="center">2015-11-13 21:56</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">5</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=5">xQ2rFOYhhUHFDWGuC9s1i2ReGkjK74ZBHWFJP3aaIotDr2U8eu</a></td>
      <td width="150" height="28" align="center">2015-11-8 21:37</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">6</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=6">jqAPG4yyvdDrj9MsJnBKRLix2x8kwsGk1XAIFwhVmQKgu2ASty</a></td>
      <td width="150" height="28" align="center">2015-11-16 19:11</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">7</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=7">upCEEJTp4UfSown2bqqVvNUsll5L4NGIbdKdRVUBmQu68E4KuZ</a></td>
      <td width="150" height="28" align="center">2015-11-15 14:05</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">8</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=8">KNAYwg9Xgt1uRIDYlbhWNCJ9FRkkNJ7S3pXvgrMRoiWQCPQsCo</a></td>
      <td width="150" height="28" align="center">2015-11-6 15:16</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">9</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=9">ggexUK2EIxaxgGclyNLarbexDERAZFCx4qpcrpxeHdYdLKQdJV</a></td>
      <td width="150" height="28" align="center">2015-11-8 20:09</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">10</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=10">9YwMPJYjpa8l5QppXW3O2HWLQyibRaiL17eTfD15tREH97HwYL</a></td>
      <td width="150" height="28" align="center">2015-11-7 12:31</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">11</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=11">GkOrNrx4dpYMemtmrfWXWvGW1goPCG8XF3zrVeWy4sZ5ghpsEA</a></td>
      <td width="150" height="28" align="center">2015-11-7 03:37</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">12</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=12">67rKBy1l7ns9KYr1QDnWDRAMbkEuzXcLTouFUurcY4tVwhREac</a></td>
      <td width="150" height="28" align="center">2015-11-7 00:31</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">13</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=13">lI6bBgge6N6RaQkUWF3UhIjcOL7lMk6hrNjUGWe3GK32RZzzii</a></td>
      <td width="150" height="28" align="center">2015-11-14 04:22</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">14</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=14">be6U3fVxTuVmZGTEtbeLxg247HQfTH2nAKKFqLhJrgGXApII23</a></td>
      <td width="150" height="28" align="center">2015-11-16 22:31</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">15</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=15">keJSJuZRqrud4dh8Fnot5qg42MU1TjExLieDvLJ4G2mBlaGnYa</a></td>
      <td width="150" height="28" align="center">2015-11-10 02:03</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">16</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=16">jeziUtWXZz5NreOgq5ZYLsjAVOY6ljzIMwq8YeQ85w1eofnxCx</a></td>
      <td width="150" height="28" align="center">2015-11-6 18:03</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">17</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=17">d4A6FoKguP9NPV8tT98V8EAvoAkSk4D8CE83O8LxpfnLEiSYqD</a></td>
      <td width="150" height="28" align="center">2015-11-12 06:25</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">18</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=18">UZbrpiWfsimB3fnwmb2SBrhX3hBfxnXsFRGbl2GeoNl7TUKrfr</a></td>
      <td width="150" height="28" align="center">2015-11-10 16:32</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">19</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=19">bFMFwD99KYFhFouxPMJgLRmOCbLb2nSzw8YQoGmxryCi3qPbGZ</a></td>
      <td width="150" height="28" align="center">2015-11-8 20:06</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">20</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=20">dks8dODBWZ6eIUErPorBplwVvfg1VSeCIKjfdghZ8n8xo5WEuq</a></td>
      <td width="150" height="28" align="center">2015-11-14 20:51</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">21</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=21">ycnxH3lMdPWJihwKmAVjOH5aYisVZqX1g5bwQ2jMzXoLccfIYc</a></td>
      <td width="150" height="28" align="center">2015-11-7 19:10</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">22</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=22">Fh8xMPRzY4kbRh8hyrcidllLoWBkXETTnNQS9TdxS169vpd2UO</a></td>
      <td width="150" height="28" align="center">2015-11-6 11:56</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">23</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=23">M6afa5QFfxlqHYjcCzlzgt71hF59Pc1fQr4TTyj7wkq9LwAGBi</a></td>
      <td width="150" height="28" align="center">2015-11-16 18:59</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">24</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=24">V35FvYkO2tIdK9UUaKSqWKDApF4VcKlUFDpzoDlymQuxPgnwfC</a></td>
      <td width="150" height="28" align="center">2015-11-11 11:30</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">25</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=25">AmjxrCQp7nRM28pZ7kDJTgGecNWDbDLBtXKmnVuCVMoCjRUKjB</a></td>
      <td width="150" height="28" align="center">2015-11-11 06:21</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">26</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=26">EXQCvfWIhDmOEQEw7AsFVSFHtWEVrOKhS4qXr3QYgZAjTFOdJJ</a></td>
      <td width="150" height="28" align="center">2015-11-16 07:09</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">27</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=27">tazNtZTB6VK38i61SiSBvALoM4Xwj4Ftv59bvVQI18XFbwNkcO</a></td>
      <td width="150" height="28" align="center">2015-11-6 19:37</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">28</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=28">ItxArkJL7dRRPIexzYfgFMcGHXkA31vTHGWxxS7PtwQsEPIFDI</a></td>
      <td width="150" height="28" align="center">2015-11-5 15:01</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">29</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=29">4iSdEtq6hrQOXao61qNblGKCCLYQMlWsE3hmiMi1CTVo9eRVWr</a></td>
      <td width="150" height="28" align="center">2015-11-15 19:01</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">30</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=30">l4DjRgvlH4vgZ9fXwGqicaxwt9kJeBEMPb2JOPb2l7V9GdBp3t</a></td>
      <td width="150" height="28" align="center">2015-11-11 12:26</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">31</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=31">qiWUobC4VFrhHgLHqqCXYlHSm2bVmxvQZhAuitU4XDaQbj1CdM</a></td>
      <td width="150" height="28" align="center">2015-11-15 10:46</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">32</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=32">U6JvVNFQpOrUKvCSr2oajA3p21HrgjrNGgQ6cuJv8PpOc8GYvK</a></td>
      <td width="150" height="28" align="center">2015-11-12 03:18</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">33</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=33">HwzLw9mEetdDGamObkhia3EDRbh6ktznro4MCaLD9kqAvrWtJP</a></td>
      <td width="150" height="28" align="center">2015-11-8 17:23</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">34</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=34">5MEfRjVTP5oBPzDbxbM6aS8J51zv69jsynz7J5OSAWAapWTLd8</a></td>
      <td width="150" height="28" align="center">2015-11-15 16:02</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">35</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=35">wtdMhDm1ad2x2FNIbkEKS37mnyWZ6Qgl2cHsJKX2MN4XDOipCj</a></td>
      <td width="150" height="28" align="center">2015-11-15 13:22</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">36</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=36">gTXiSTmxveeRyVwe9qa1cbNLOp7loeSaog4jsRuyvqeAjTrj3s</a></td>
      <td width="150" height="28" align="center">2015-11-16 21:49</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">37</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=37">riBdmZOIvRaxxm7QkocaLLMnABtEvWhdqhu13lMAkfsQvtvzsE</a></td>
      <td width="150" height="28" align="center">2015-11-6 08:02</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">38</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=38">SgROoELUgxksCMXjyQgqwyzt4kyZP1pJmSAphdq7nsTqZIFzAX</a></td>
      <td width="150" height="28" align="center">2015-11-11 17:56</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">39</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=39">wBCVMZtT3gSgaS8yDLBHr64yJto4gE1g63xGR2LjuhoHUaq11A</a></td>
      <td width="150" height="28" align="center">2015-11-8 22:51</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">40</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=40">LoMYrhCAIeLwkKIX9qOjmuFUTXiqdsNHoyo3bH75IKc1LvErRb</a></td>
      <td width="150" height="28" align="center">2015-11-11 14:54</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">41</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=41">H13mBJ8Q9NjW454Vxu3zo6hcCU4XgEF927LI1j7iFNgQwuSNOs</a></td>
      <td width="150" height="28" align="center">2015-11-7 12:58</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">42</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=42">ofJHLRKlQkNVSoict2fKsksyVwFsgGGhcsM2RrjPRfIBJaC728</a></td>
      <td width="150" height="28" align="center">2015-11-11 16:36</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">43</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=43">WDV6BU9OFwFTs5wcoSTdZ4wGJayBggFgrWarnFDM2aTK39Lgsi</a></td>
      <td width="150" height="28" align="center">2015-11-14 19:16</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">44</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=44">YCKJoEw8dR8kzIDQI7ohYaKflHfzTu3qsH9h3ugU3A9BX9dOmd</a></td>
      <td width="150" height="28" align="center">2015-11-16 21:20</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">45</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=45">ZOhSNjg5Ci4hthWQHfSMtoAkdPooOGQgu2d4lAHquoP8wHuv3N</a></td>
      <td width="150" height="28" align="center">2015-11-5 11:13</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">46</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=46">BRGRrRCgWWkYMcXwOFz3EzUi8MRFGaBjpCOfdDcfpdkRNE6LA8</a></td>
      <td width="150" height="28" align="center">2015-11-10 01:51</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">47</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=47">aknkIhUHrxfpm86MMLFlyfNGxsWRlq28gTvmMqugxbp9Q22TcS</a></td>
      <td width="150" height="28" align="center">2015-11-11 18:28</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">48</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=48">DBFxne5znXV6Katd5qoIaRB13zW9YL9zxmELYFerHy6V53e4Br</a></td>
      <td width="150" height="28" align="center">2015-11-12 19:43</td>
    </tr>
    <tr bgcolor="#FFFFFF">
      <td width="70" height="28" align="center">49</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=49">7EYSDEtlH52U2n4G2quUHckRUYHvTt2YrpmVsxKYxJyITMjfu9</a></td>
      <td width="150" height="28" align="center">2015-11-10 14:32</td>
    </tr>
    <tr bgcolor="#EEEEEE">
      <td width="70" height="28" align="center">50</td>
      <td height="28" align="left" style="font-size:14px"><a href="item.php?i=50">banvniEgt1KCCoddxSOgu8My69HTaioGDUBzHABHpkLWntF7j5</a></td>
      <td width="150" height="28" align="center">2015-11-7 06:20</td>
    </tr>
  </tbody>
</table>
</body>
</html>

一派護法 十九級
6樓 發表于:2015-11-16 23:10
其採取的方法是:把gettext調用的代碼塊由<?=_('text')?>改成{*text},如果遇到參數,比如<?=_('%d posts', $postsNum)?>,那麼就改成{1*%d posts},然後在strCenter函數中處理caseID為1的情況下的sprintf參數替換。
在倒數第四排$reg正則表達式中的方括號[]內,可以指定檢測{}中的字符列表。
一派護法 十九級
7樓 發表于:2015-11-16 23:11
這樣一來,就完美解決了網站使用gettext實現了國際化之後,Dreamweaver的設計視圖里卻只有一堆PHP代碼塊的嚴重問題。
一派護法 十九級
8樓 發表于:2015-11-16 23:14
由於每個頁面都這樣寫比較麻煩,大家可以考慮把這些代碼,包括strCenter函數在內,封裝成一個PHP類。
一派護法 十九級
9樓 發表于:2015-11-17 11:12
{|Title of table}
{2|This could be better.}
{Omitted}
感觉把匹配模式定义成这样会比较好。
一派護法 十九級
10樓 發表于:2015-11-17 11:15
{2|This could be better.}
其中的2是sprintf编号。该编号在不同页面中可以重复使用,但是mo文件中的msgid无需包含该编号,只需要写msgid "This could be better."就行。
这种方法关键要注意防止破坏css和js代码。
一派護法 十九級
11樓 發表于:2015-11-17 11:16
{|Title of table} 编号为0
{2|This could be better.} 编号为2
{Omitted} 没有编号

回復帖子

內容:
用戶名: 您目前是匿名發表
驗證碼:
(快捷鍵:Ctrl+Enter)
 

本帖信息

點擊數:779 回複數:10
評論數: ?
作者:巨大八爪鱼
最後回復:巨大八爪鱼
最後回復時間:2015-11-17 11:16
 
©2010-2024 Arslanbar Ver2.0
除非另有聲明,本站採用創用CC姓名標示-相同方式分享 3.0 Unported許可協議進行許可。