Posts Tagged ‘ Coding

[转载][MySQL]MySQL 的 SET NAMES xxx 字符编码问题分析

转载自: PHPChina


近来接受 BBT 的培训,做一个投票系统。系统程式码倒不是很难,但是我的时间主要花费在了研究字符集和编码上面。MySQL 和 Apache 两个系统的编码 (字符集) 问题让我费劲脑筋,吃尽苦头。网上对这些问题的解决比较零散,比较片面,大部分是提供解决方法,却不说为什么。于是我将这几天收获总结一下,避免后来者再走弯路。这篇文章对 PHP 编写有一点帮助 (看完你就知道,怎样让你的 PHP 程式在大部分空间提供商的服务器里显示正常),但是更多帮助在于网络服务器的架设和设置。
Read more

[JavaScript]动态网页设计的相关网页 (dhtml)

国外网站

中文网站

其它

[Perl][JavaScript]以数学的原理处理四舍五入

我看过太多人都把四舍五入的问题看成是“字串”来处理,实际上,如果把四舍五入做为“数学”来解的话,程式大概只要几行即可解决。

以四舍五入取整数的例子来讲,其原理就是: 任何数值 +0.5 再取整数

但要注意的是,当四舍五入遇到“负数”时就会变成“五舍六入”,这是因为中间数要往数值大的那边进位的缘故。所以加上了负数的处理,程式至少又多了一行:
Read more

在 Blogger 中使用 dp.SyntaxHighlighter 显示程式码

db.SyntaxHighlighter 是一支不错的程式码高亮度显示程式,特点为:

  1. 显示行号
  2. 支援12种程式语言
  3. 模组化加载需要的程式语言
  4. 支援 “<pre>” 及 “<textarea>” 区块
  5. 纯文字检视
  6. 复制到剪贴簿
  7. 直接打印程式码

缺点就是加载速度较慢。

安装步骤

  1. 修改 blogger 样板,搜寻 “</body>”,在 “上方” 加入(你可以选择你要的语言加载即可):
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shCore.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushPhp.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushJScript.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushSql.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushXml.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushDelphi.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushPython.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushRuby.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushCss.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushCpp.js'></script>
    <script class='javascript'>
    dp.SyntaxHighlighter.ClipboardSwf = 'http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/clipboard.swf';
    dp.SyntaxHighlighter.HighlightAll('code');
    </script>

    (因为 “偷吃步” 的关系,程式直接连到 dp.SyntaxHighlighter 的 SVN 上,你可以视情况下载回来放到自己的服务器)

  2. dp.SyntaxHighlighter 原本已经有一个 CSS 档了,但如果将这个 CSS 档以 “Link” 的方式加载,却无法正常显示。所以,请自行增加下列 CSS 到 blogger 样板的 CSS 区段:
    /*dp.highlighter*/
    .dp-highlighter {
      font-family: "Consolas", "Courier New", Courier, mono;
      font-size: 12px;
      background-color: #E7E5DC;
      width: 99%;
      overflow: auto;
      margin: 18px 0px 18px 0px;
      padding-top: 1px; /* adds a little border on top when controls are hidden */
      border:1px inset;
      max-height:200px;
    }
    .dp-highlighter .bar {
      padding-left: 45px;
    }
    .dp-highlighter.collapsed .bar,
    .dp-highlighter.nogutter .bar {
      padding-left: 0px;
    }
    .dp-highlighter ol {
      list-style: decimal; /* for ie */
      list-style: decimal-leading-zero; /* better look for others */
      background-color: #fff;
      margin: 0px 0px 1px 45px; /* 1px bottom margin seems to fix occasional Firefox scrolling */
      padding: 0px;
      color: #5C5C5C;
    }
    .dp-highlighter.nogutter ol {
      list-style-type: none !important;
      margin-left: 0px;
    }
    .dp-highlighter ol li,
    .dp-highlighter .columns div {
      border-left: 3px solid #6CE26C;
      background-color: #f8f8f8;
      padding-left: 10px;
      line-height: 14px;
    }
    .dp-highlighter.nogutter ol li,
    .dp-highlighter.nogutter .columns div {
      border: 0;
    }
    .dp-highlighter .columns {
      color: gray;
      overflow: hidden;
      width: 100%;
    }
    .dp-highlighter .columns div {
      padding-bottom: 5px;
    }
    .dp-highlighter ol li.alt {
      background-color: #fff;
    }
    .dp-highlighter ol li span {
      color: Black;
    }
    /* Adjust some properties when collapsed */
    .dp-highlighter.collapsed ol {
      margin: 0px;
    }
    .dp-highlighter.collapsed ol li {
      display: none;
    }
    /* Additional modifications when in print-view */
    .dp-highlighter.printing {
      border: none;
    }
    .dp-highlighter.printing .tools {
      display: none !important;
    }
    .dp-highlighter.printing li {
      display: list-item !important;
    }
    /* Styles for the tools */
    .dp-highlighter .tools {
      padding: 3px 8px 3px 10px;
      font: 9px Verdana, Geneva, Arial, Helvetica, sans-serif;
      color: silver;
      background-color: #f8f8f8;
      text-align1: right;
      padding-bottom: 10px;
      border-left: 3px solid #6CE26C;
    }
    .dp-highlighter.nogutter .tools {
      border-left: 0;
    }
    .dp-highlighter.collapsed .tools {
      border-bottom: 0;
    }
    .dp-highlighter .tools a {
      font-size: 9px;
      color: #a0a0a0;
      text-decoration: none;
      margin-right: 10px;
    }
    .dp-highlighter .tools a:hover {
      color: red;
      text-decoration: underline;
    }
    /* About dialog styles */
    .dp-about { background-color: #fff; margin: 0px; padding: 0px; }
    .dp-about table { width: 100%; height: 100%; font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; }
    .dp-about td { padding: 10px; vertical-align: top; }
    .dp-about .copy { border-bottom: 1px solid #ACA899; height: 95%; }
    .dp-about .title { color: red; font-weight: bold; }
    .dp-about .para { margin: 0 0 4px 0; }
    .dp-about .footer { background-color: #ECEADB; border-top: 1px solid #fff; text-align: right; }
    .dp-about .close { font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; background-color: #ECEADB; width: 60px; height: 22px; }
    /* Language specific styles */
    .dp-highlighter .comment, .dp-highlighter .comments { color: #008200; }
    .dp-highlighter .string { color: blue; }
    .dp-highlighter .keyword { color: #069; font-weight: bold; }
    .dp-highlighter .preprocessor { color: gray; }
  3. 储存即可

使用方法

  • 方法一 - 使用 “<textarea>” 区块,需将 “&” 转换为 “&amp;”:
    <textarea name="code" class="程式语言">
    程式码
    </textarea>
  • 方法二 - 使用 “<pre>” 区块,需将 “&” 转换为 “&amp;”、”<” 转换为 “&lt;”、”>” 转换为 “&gt;”:
    <pre name="code" class="程式语言">
    程式码
    </pre>

参考网页

在 Blogger 中使用 google-code-prettify 显示程式码

google-code-prettify 是一支不错的程式码高亮度显示程式,特点为:

  1. 支援 15 种程式语言(但某些语言似乎还没完成)
  2. 程式仅两个档案
  3. 加载速度较快

缺点为:

  1. 跟 IE 的相容性比较不佳,在 IE 内复制程式码时无换行符号
  2. 无行号显示
  3. 仅支援 "<pre>" 区块
  4. 程式码过长时不会自动显示卷轴 (可透过修改 CSS 解决)

安装步骤

  1. 修改 blogger 样板,搜寻 "</head>",在 "上方" 加入
    <link href='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css' type='text/css' rel='stylesheet' />
    <script type='text/javascript' src='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js'></script>

    (因为 "偷吃步" 的关系,程式直接连到 google-code-prettify 的 SVN 上,你可以视情况下载回来放到自己的服务器)

  2. 继续搜寻 "<body>",在标签内的 onload 事件加入:
    prettyPrint();
  3. 储存即可。

使用方法

      使用 "<pre>" 区块,需将 "&" 转换为 "&amp;"、"<" 转换为 "&lt;"、">" 转换为 "&gt;":
<pre class="prettyprint">
程式码
</pre>

参考网页

[Perl]Perl 的相关网页资源

手册

教学/手册

Read more

几种网页转址与“301 永久搬移”的语法

转址的方式分为:

  • 302: 暂时搬移 (Temporarily Moved)
  • 301: 永久搬移 (Permanently Moved)

Read more

各种资料手册下载,强力推荐

Cheat Sheet Roundup 是一个很棒的网站,内有作业系统、程式设计、数据库、网页设计…等 30 余种相关的资料手册可供下载(包含一些单页的 Data Sheet 可以用来贴在自己的座位墙板上),对于设计师与相关资讯人员,都是很好的参考资料,强力推荐。

看看人家的程式是怎么写的

在国外有一些网站,专门存放一些程式码的精华片段,写程式如果遇到瓶颈,可以上来逛逛…

Coding

Regular Expression

[转载][Perl][PHP]描述语言成软件开发新宠

转载自: CNet


过去曾经被专业程式设计师视为太简单的描述语言(scripting languages),正逐渐成为企业软件开发界里的一等公民。

数据库大厂甲骨文(Oracle)要在周一宣布一项合作案,可望能够让采用Zend Technologies 公司PHP工具的企业,更容易建立客制化的应用。PHP是一种用来设计网页的开放原始码描述语言。

除了甲骨文的加码PHP之外,近来软件大厂如IBM、升阳(Sun),及微软,也都大力投入越来越受欢迎的描述语言,或者也称“动态”(dynamic)语言。

描述语言过去以来已经用在网络上各种应用的设计上,但是一般而言,企业开发者并未广为采用。但是近来有越来越多的企业与IT专业从业者寻求以这种语言,做为简化与加速公司内客制化程式的方法,藉以避免近来普遍存在的应用软件过于庞大或预算暴增的问题。

“描述语言越来越受欢迎而且越来越强大,只因为它太容易使用了。”顾问公司InterKnowlogy执行长Tim Huckaby表示。“这跟完成时机与金钱有关,而非关底层究竟有多优雅。”

借由与Zend的合作,甲骨文赶搭PHP的这股风潮,并鼓励Oracle数据库的使用。根据Zend行销副总裁Pamela Roussos表示,目前,Zend客户有20%以上使用Oracle数据库。

同时甲骨文也可吸引较小型的公司企业而扩大其客户群──这些客户通常缺乏强大的IT部门以一些知名的程式语言来打造庞大的客制化商业应用软件。相较于较为 复杂的Java、C、C++,及Visual Basic,描述语言可以不需要电脑科学学历或太多的专业训练即可广被采用。

甲骨文用来执行客制化商业应用的自家开发工具及相关的“中介软件”都是以Java为基础。同样的,IBM、BEA、升阳等厂商也都持续在投资Java标准。另一方面,微软的工具则是以它专属的“.Net”软件为基础。

Zend采用开放原始码的PHP软件并专门为企业开发者提供开发工具。

Read more

return top