php操作office文档

PhpStorm中文汉化

一个翻译github的脚本

把下面的代码另存为github.user.js, 然后拖拽到chrome的插件管理界面, 打开github就可以看到中文的github了

  1. (function() {
  2. var url_has = function(str) {
  3. return location.href.indexOf(str) >= 0;
  4. }
  5. var $ = function(selector) {
  6. return document.querySelectorAll(selector);
  7. };
  8. var replace_dom = function(selector, num, attr, old_string, new_string) {
  9. var selector_str = selector;
  10. if (typeof selector == 'string') {
  11. selector = $(selector);
  12. }
  13. var rep = function(str) {
  14. str = str || '';
  15. if (typeof new_string == 'undefined') {
  16. for (var j in old_string) {
  17. str = str.replace(old_string[j][0], old_string[j][1]);
  18. }
  19. } else {
  20. str = str.replace(old_string, new_string);
  21. }
  22. return str;
  23. }
  24. if (num === 'each') {
  25. for (var i in selector) {
  26. selector[i][attr] = rep(selector[i][attr]);
  27. }
  28. } else if (selector.length && (num in selector) && (attr in selector[num])) {
  29. selector[num][attr] = rep(selector[num][attr]);
  30. }
  31. if (typeof selector_str == 'string') {
  32. setTimeout(function() {
  33. replace_dom(selector_str, num, attr, old_string, new_string);
  34. }, 1000);
  35. }
  36. };
  37. if (!url_has('github.com')) {
  38. return;
  39. }
  40. // 搜索框
  41. replace_dom($('.header-search-input'), 0, 'placeholder', 'Search GitHub', '全站搜索');
  42. // 翻译导航 Pull requests, Issues, Gist
  43. replace_dom($('.header-nav a'), 2, 'innerHTML', 'Gist', '重点');
  44. // 首页的两个大按钮
  45. replace_dom($('.shelf-cta'), 0, 'innerHTML', 'Read the guide', '阅读指南');
  46. replace_dom($('.shelf-cta'), 1, 'innerHTML', 'Start a project', '开始一个项目');
  47. // 首页我贡献的
  48. replace_dom($('[role=navigation] h3'), 0, 'innerHTML', 'Repositories you contribute to', '你有贡献的库');
  49. // 首页我的仓库
  50. replace_dom($('#your_repos'), 0, 'innerHTML', 'Your repositories', '你的仓库');
  51. replace_dom($('#your_repos a'), 0, 'innerHTML', 'New repository', '新建仓库');
  52. replace_dom($('.repo-filter'), 0, 'innerHTML', 'All', '全部');
  53. replace_dom($('.repo-filter'), 1, 'innerHTML', 'Public', '公开');
  54. replace_dom($('.repo-filter'), 2, 'innerHTML', 'Private', '私有');
  55. replace_dom($('.repo-filter'), 3, 'innerHTML', 'Sources', '创建的');
  56. replace_dom($('.repo-filter'), 4, 'innerHTML', 'Forks', '克隆的');
  57. replace_dom($('#your-repos-filter'), 0, 'placeholder', 'Find a repository', '搜索仓库');
  58. // document.querySelector('.file-navigation i').innerHTML = '分支:';
  59. // 翻译提交时间
  60. replace_dom('relative-time,time-ago', 'each', 'innerHTML', [
  61. ['minutes ago', '分钟前'],
  62. ['an hour ago', '1小时前'],
  63. ['hours ago', '小时前'],
  64. ['a day ago', '一天前'],
  65. ['days ago', '天前'],
  66. ['a month ago', '1个月前'],
  67. ['months ago', '个月前'],
  68. [/^on\s(\d+)\sJan/, '1月$1号'],
  69. [/^on\s(\d+)\sFeb/, '2月$1号'],
  70. [/^on\s(\d+)\sMar/, '3月$1号'],
  71. [/^on\s(\d+)\sApr/, '4月$1号'],
  72. [/^on\s(\d+)\sMay/, '5月$1号'],
  73. [/^on\s(\d+)\sJun/, '6月$1号'],
  74. [/^on\s(\d+)\sJul/, '7月$1号'],
  75. [/^on\s(\d+)\sAug/, '8月$1号'],
  76. [/^on\s(\d+)\sSep/, '9月$1号'],
  77. [/^on\s(\d+)\sOct/, '10月$1号'],
  78. [/^on\s(\d+)\sNov/, '11月$1号'],
  79. [/^on\s(\d+)\sDec/, '12月$1号']
  80. ]);
  81. // 翻译提交时间
  82. replace_dom($('.commit-group-title'), 'each', 'innerHTML', [
  83. ['Commits on', '提交时间: '],
  84. [/Jan\s(\d+)\,\s(\d+)/, '$2年1月$1号'],
  85. [/Feb\s(\d+)\,\s(\d+)/, '$2年2月$1号'],
  86. [/Mar\s(\d+)\,\s(\d+)/, '$2年3月$1号'],
  87. [/Apr\s(\d+)\,\s(\d+)/, '$2年4月$1号'],
  88. [/May\s(\d+)\,\s(\d+)/, '$2年5月$1号'],
  89. [/Jun\s(\d+)\,\s(\d+)/, '$2年6月$1号'],
  90. [/Jul\s(\d+)\,\s(\d+)/, '$2年7月$1号'],
  91. [/Aug\s(\d+)\,\s(\d+)/, '$2年8月$1号'],
  92. [/Sep\s(\d+)\,\s(\d+)/, '$2年9月$1号'],
  93. [/Oct\s(\d+)\,\s(\d+)/, '$2年10月$1号'],
  94. [/Nov\s(\d+)\,\s(\d+)/, '$2年11月$1号'],
  95. [/Dec\s(\d+)\,\s(\d+)/, '$2年12月$1号']
  96. ]);
  97. // 创建新仓库页面
  98. replace_dom($('.subhead-heading'), 0, 'innerHTML', 'Create a new repository', '创建一个新的存储库');
  99. replace_dom($('.subhead-description'), 0, 'innerHTML', 'A repository contains all the files for your project, including the revision history.', '一个存储库包含您的项目的所有文件,包括修改历史记录。');
  100. replace_dom($('.owner-reponame label'), 0, 'innerHTML', 'Owner', '所有者');
  101. replace_dom($('.owner-reponame label'), 1, 'innerHTML', 'Repository name', '仓库名称');
  102. replace_dom($('.with-permission-fields .my-3'), 0, 'innerHTML', 'Great repository names are short and memorable. Need inspiration? How about', '一个存储库包含您的项目的所有文件,包括修改历史记录。');
  103. replace_dom($('.select-menu-title'), 0, 'innerHTML', 'Choose another owner', '选择其他所有者');
  104. replace_dom($('[for=repository_description]'), 0, 'innerHTML', 'Description', '描述');
  105. // replace_dom($('.with-permission-fields .form-checkbox label :nth-child(3)'), 0, 'textContent', 'Public', '公开');
  106. replace_dom($('.with-permission-fields .form-checkbox .note'), 0, 'innerHTML', 'Anyone can see this repository. You choose who can commit.', '公开: 任何人都可以看到这个库。你可以选择谁能提交。');
  107. // replace_dom($('.with-permission-fields .form-checkbox label :nth-child(3)'), 0, 'textContent', 'Private', '私有');
  108. replace_dom($('.with-permission-fields .form-checkbox .note'), 1, 'innerHTML', 'You choose who can see and commit to this repository.', '私有: 您选择谁可以看到并提交到这个存储库。');
  109. // 版本库首页
  110. replace_dom($('.header-search-scope'), 0, 'innerHTML', [
  111. ['This repository', '搜索当前仓库'],
  112. ['This organization', '搜索当前组织']
  113. ]);
  114. replace_dom($('.numbers-summary li:nth-child(1) a'), 0, 'innerHTML', 'commits', '次提交');
  115. replace_dom($('.numbers-summary li:nth-child(2) a'), 0, 'innerHTML', 'branch', '个分支');
  116. replace_dom($('.numbers-summary li:nth-child(3) a'), 0, 'innerHTML', 'releases', '个版本');
  117. replace_dom($('.numbers-summary li:nth-child(4) a'), 0, 'innerHTML', 'contributors', '个贡献者');
  118. replace_dom('#context-commitish-filter-field', 0, 'placeholder', [
  119. ['Filter branches/tags', '搜索分支标签'],
  120. ['Find a tag', '搜索标签']
  121. ]);
  122. replace_dom($('h3'), 'each', 'innerHTML', [
  123. ['Watched repositories', '监控的版本库'],
  124. ]);
  125. replace_dom($('button,a,span,i'), 'each', 'innerHTML', [
  126. ['New pull request', '新拉取请求'],
  127. [' Projects', ' 项目'],
  128. [' Pulse', ' 脉冲'],
  129. [' branch', ' 分支'],
  130. ['Graphs', '图表'],
  131. ['Settings', '设置'],
  132. ['Pull requests', '拉取请求'],
  133. ['Change notification settings', '更改通知设置'],
  134. ['Unread', '未读'],
  135. ['Unwatch all', '取消全部监控'],
  136. ['Unwatch', '取消监控'],
  137. ['Not watching', '不监控'],
  138. ['Participating', '参与'],
  139. ['Mark all as read', '标记全部为已读'],
  140. ['All notifications', '所有通知'],
  141. ['Notifications', '通知'],
  142. ['Watching', '监控'],
  143. ['Learn more', '加载更多'],
  144. ['New repository', '新建仓库'],
  145. ['New team', '新建团队'],
  146. ['My teams', '我的团队'],
  147. ['Repositories', '仓库'],
  148. ['People', '成员'],
  149. ['Teams', '团队'],
  150. ['Use SSH', '使用SSH协议'],
  151. ['Use HTTPS', '使用HTTPS协议'],
  152. ['Create new file', '创建新文件'],
  153. ['Upload files', '上传文件'],
  154. ['Find file', '搜索文件'],
  155. ['Issues', '问题'],
  156. ['Code', '代码'],
  157. ['Wiki', '维基'],
  158. ['Contact GitHub', '联系GitHub'],
  159. ['Training', '培养'],
  160. ['Blog', '博客'],
  161. ['Shop', '商店'],
  162. ['About', '关于'],
  163. ['Labels', '标签'],
  164. ['Milestones', '里程碑'],
  165. ['Filters', '搜索'],
  166. ['Clone or download', '克隆或下载'],
  167. ['Branches', '分支'],
  168. ['Branch:', '分支:'],
  169. ['Tags', '标签'],
  170. ['Download ZIP', '下载ZIP压缩包'],
  171. ['Switch branches/tags', '切换分支或标签']
  172. ]);
  173. })();

一个翻译github的脚本

  1. (function() {
  2. var url_has = function(str) {
  3. return location.href.indexOf(str) >= 0;
  4. }
  5. var $ = function(selector) {
  6. return document.querySelectorAll(selector);
  7. };
  8. var replace_dom = function(selector, num, attr, old_string, new_string) {
  9. var selector_str = selector;
  10. if (typeof selector == 'string') {
  11. selector = $(selector);
  12. }
  13. var rep = function(str) {
  14. str = str || '';
  15. if (typeof new_string == 'undefined') {
  16. for (var j in old_string) {
  17. str = str.replace(old_string[j][0], old_string[j][1]);
  18. }
  19. } else {
  20. str = str.replace(old_string, new_string);
  21. }
  22. return str;
  23. }
  24. if (num === 'each') {
  25. for (var i in selector) {
  26. selector[i][attr] = rep(selector[i][attr]);
  27. }
  28. } else if (selector.length && (num in selector) && (attr in selector[num])) {
  29. selector[num][attr] = rep(selector[num][attr]);
  30. }
  31. if (typeof selector_str == 'string') {
  32. setTimeout(function() {
  33. replace_dom(selector_str, num, attr, old_string, new_string);
  34. }, 1000);
  35. }
  36. };
  37. if (!url_has('github.com')) {
  38. return;
  39. }
  40. // 搜索框
  41. replace_dom($('.header-search-input'), 0, 'placeholder', 'Search GitHub', '全站搜索');
  42. // 翻译导航 Pull requests, Issues, Gist
  43. replace_dom($('.header-nav a'), 2, 'innerHTML', 'Gist', '重点');
  44. // 首页的两个大按钮
  45. replace_dom($('.shelf-cta'), 0, 'innerHTML', 'Read the guide', '阅读指南');
  46. replace_dom($('.shelf-cta'), 1, 'innerHTML', 'Start a project', '开始一个项目');
  47. // 首页我贡献的
  48. replace_dom($('[role=navigation] h3'), 0, 'innerHTML', 'Repositories you contribute to', '你有贡献的库');
  49. // 首页我的仓库
  50. replace_dom($('#your_repos'), 0, 'innerHTML', 'Your repositories', '你的仓库');
  51. replace_dom($('#your_repos a'), 0, 'innerHTML', 'New repository', '新建仓库');
  52. replace_dom($('.repo-filter'), 0, 'innerHTML', 'All', '全部');
  53. replace_dom($('.repo-filter'), 1, 'innerHTML', 'Public', '公开');
  54. replace_dom($('.repo-filter'), 2, 'innerHTML', 'Private', '私有');
  55. replace_dom($('.repo-filter'), 3, 'innerHTML', 'Sources', '创建的');
  56. replace_dom($('.repo-filter'), 4, 'innerHTML', 'Forks', '克隆的');
  57. replace_dom($('#your-repos-filter'), 0, 'placeholder', 'Find a repository', '搜索仓库');
  58. // document.querySelector('.file-navigation i').innerHTML = '分支:';
  59. // 翻译提交时间
  60. replace_dom('relative-time,time-ago', 'each', 'innerHTML', [
  61. ['minutes ago', '分钟前'],
  62. ['an hour ago', '1小时前'],
  63. ['hours ago', '小时前'],
  64. ['a day ago', '一天前'],
  65. ['days ago', '天前'],
  66. ['a month ago', '1个月前'],
  67. ['months ago', '个月前'],
  68. [/^on\s(\d+)\sJan/, '1月$1号'],
  69. [/^on\s(\d+)\sFeb/, '2月$1号'],
  70. [/^on\s(\d+)\sMar/, '3月$1号'],
  71. [/^on\s(\d+)\sApr/, '4月$1号'],
  72. [/^on\s(\d+)\sMay/, '5月$1号'],
  73. [/^on\s(\d+)\sJun/, '6月$1号'],
  74. [/^on\s(\d+)\sJul/, '7月$1号'],
  75. [/^on\s(\d+)\sAug/, '8月$1号'],
  76. [/^on\s(\d+)\sSep/, '9月$1号'],
  77. [/^on\s(\d+)\sOct/, '10月$1号'],
  78. [/^on\s(\d+)\sNov/, '11月$1号'],
  79. [/^on\s(\d+)\sDec/, '12月$1号']
  80. ]);
  81. // 翻译提交时间
  82. replace_dom($('.commit-group-title'), 'each', 'innerHTML', [
  83. ['Commits on', '提交时间: '],
  84. [/Jan\s(\d+)\,\s(\d+)/, '$2年1月$1号'],
  85. [/Feb\s(\d+)\,\s(\d+)/, '$2年2月$1号'],
  86. [/Mar\s(\d+)\,\s(\d+)/, '$2年3月$1号'],
  87. [/Apr\s(\d+)\,\s(\d+)/, '$2年4月$1号'],
  88. [/May\s(\d+)\,\s(\d+)/, '$2年5月$1号'],
  89. [/Jun\s(\d+)\,\s(\d+)/, '$2年6月$1号'],
  90. [/Jul\s(\d+)\,\s(\d+)/, '$2年7月$1号'],
  91. [/Aug\s(\d+)\,\s(\d+)/, '$2年8月$1号'],
  92. [/Sep\s(\d+)\,\s(\d+)/, '$2年9月$1号'],
  93. [/Oct\s(\d+)\,\s(\d+)/, '$2年10月$1号'],
  94. [/Nov\s(\d+)\,\s(\d+)/, '$2年11月$1号'],
  95. [/Dec\s(\d+)\,\s(\d+)/, '$2年12月$1号']
  96. ]);
  97. // 创建新仓库页面
  98. replace_dom($('.subhead-heading'), 0, 'innerHTML', 'Create a new repository', '创建一个新的存储库');
  99. replace_dom($('.subhead-description'), 0, 'innerHTML', 'A repository contains all the files for your project, including the revision history.', '一个存储库包含您的项目的所有文件,包括修改历史记录。');
  100. replace_dom($('.owner-reponame label'), 0, 'innerHTML', 'Owner', '所有者');
  101. replace_dom($('.owner-reponame label'), 1, 'innerHTML', 'Repository name', '仓库名称');
  102. replace_dom($('.with-permission-fields .my-3'), 0, 'innerHTML', 'Great repository names are short and memorable. Need inspiration? How about', '一个存储库包含您的项目的所有文件,包括修改历史记录。');
  103. replace_dom($('.select-menu-title'), 0, 'innerHTML', 'Choose another owner', '选择其他所有者');
  104. replace_dom($('[for=repository_description]'), 0, 'innerHTML', 'Description', '描述');
  105. // replace_dom($('.with-permission-fields .form-checkbox label :nth-child(3)'), 0, 'textContent', 'Public', '公开');
  106. replace_dom($('.with-permission-fields .form-checkbox .note'), 0, 'innerHTML', 'Anyone can see this repository. You choose who can commit.', '公开: 任何人都可以看到这个库。你可以选择谁能提交。');
  107. // replace_dom($('.with-permission-fields .form-checkbox label :nth-child(3)'), 0, 'textContent', 'Private', '私有');
  108. replace_dom($('.with-permission-fields .form-checkbox .note'), 1, 'innerHTML', 'You choose who can see and commit to this repository.', '私有: 您选择谁可以看到并提交到这个存储库。');
  109. // 版本库首页
  110. replace_dom($('.header-search-scope'), 0, 'innerHTML', [
  111. ['This repository', '搜索当前仓库'],
  112. ['This organization', '搜索当前组织']
  113. ]);
  114. replace_dom($('.numbers-summary li:nth-child(1) a'), 0, 'innerHTML', 'commits', '次提交');
  115. replace_dom($('.numbers-summary li:nth-child(2) a'), 0, 'innerHTML', 'branch', '个分支');
  116. replace_dom($('.numbers-summary li:nth-child(3) a'), 0, 'innerHTML', 'releases', '个版本');
  117. replace_dom($('.numbers-summary li:nth-child(4) a'), 0, 'innerHTML', 'contributors', '个贡献者');
  118. replace_dom('#context-commitish-filter-field', 0, 'placeholder', [
  119. ['Filter branches/tags', '搜索分支标签'],
  120. ['Find a tag', '搜索标签']
  121. ]);
  122. replace_dom($('h3'), 'each', 'innerHTML', [
  123. ['Watched repositories', '监控的版本库'],
  124. ]);
  125. replace_dom($('button,a,span,i'), 'each', 'innerHTML', [
  126. ['New pull request', '新拉取请求'],
  127. [' Projects', ' 项目'],
  128. [' Pulse', ' 脉冲'],
  129. [' branch', ' 分支'],
  130. ['Graphs', '图表'],
  131. ['Settings', '设置'],
  132. ['Pull requests', '拉取请求'],
  133. ['Change notification settings', '更改通知设置'],
  134. ['Unread', '未读'],
  135. ['Unwatch all', '取消全部监控'],
  136. ['Unwatch', '取消监控'],
  137. ['Not watching', '不监控'],
  138. ['Participating', '参与'],
  139. ['Mark all as read', '标记全部为已读'],
  140. ['All notifications', '所有通知'],
  141. ['Notifications', '通知'],
  142. ['Watching', '监控'],
  143. ['Learn more', '加载更多'],
  144. ['New repository', '新建仓库'],
  145. ['New team', '新建团队'],
  146. ['My teams', '我的团队'],
  147. ['Repositories', '仓库'],
  148. ['People', '成员'],
  149. ['Teams', '团队'],
  150. ['Use SSH', '使用SSH协议'],
  151. ['Use HTTPS', '使用HTTPS协议'],
  152. ['Create new file', '创建新文件'],
  153. ['Upload files', '上传文件'],
  154. ['Find file', '搜索文件'],
  155. ['Issues', '问题'],
  156. ['Code', '代码'],
  157. ['Wiki', '维基'],
  158. ['Contact GitHub', '联系GitHub'],
  159. ['Training', '培养'],
  160. ['Blog', '博客'],
  161. ['Shop', '商店'],
  162. ['About', '关于'],
  163. ['Labels', '标签'],
  164. ['Milestones', '里程碑'],
  165. ['Filters', '搜索'],
  166. ['Clone or download', '克隆或下载'],
  167. ['Branches', '分支'],
  168. ['Branch:', '分支:'],
  169. ['Tags', '标签'],
  170. ['Download ZIP', '下载ZIP压缩包'],
  171. ['Switch branches/tags', '切换分支或标签']
  172. ]);
  173. })();

Ubuntu 的 https协议 和 反向代理

下面假设你的域名是 git.ngapp.net , 配置服务器用 Ubuntu + Apache

ssl免费证书申请:

  1. 沃通提供的免费ssl证书: https://buy.wosign.com/free/
  2. 解压复制apache需要的文件到 /etc/apache2/ssl 目录

配置Apache

增加配置 /etc/apache2/apache2.conf
  1. ServiceName localhost
开启需要的模块
  1. a2enmod ssl
  2. a2enmod proxy
  3. a2enmod proxy_http
添加配置 /etc/apache2/sites-enabled/git.ngapp.net.conf
  1. <VirtualHost *:443>
  2. SSLEngine On
  3. SSLCertificateFile /etc/apache2/ssl/git.ngapp.net.crt
  4. SSLCertificateKeyFile /etc/apache2/ssl/git.ngapp.net.key
  5. SSLCertificateChainFile /etc/apache2/ssl/root_bundle.crt
  6. ServerName git.ngapp.net
  7. ServerAdmin zhaishuaigan@qq.com
  8. ProxyPreserveHost On
  9. ProxyRequests Off
  10. <Proxy *>
  11. AddDefaultCharset off
  12. Order deny,allow
  13. Allow from all
  14. </Proxy>
  15. ProxyPass / http://localhost:3000/
  16. ProxyPassReverse / http://localhost:3000/
  17. </VirtualHost>
  18. <VirtualHost *:80>
  19. ServerName git.ngapp.net
  20. ServerAdmin zhaishuaigan@qq.com
  21. RewriteEngine on
  22. RewriteCond %{SERVER_PORT} !^443$
  23. RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
  24. </VirtualHost>

解决手机网页click事件的300毫秒延时问题

这里我不讨论为什么手机端有300毫秒延时, 只说解决方法, 需要知道为什么的小伙伴可以自己百度.

直接上解决方法

  1. 下载引入fastclick.js : https://github.com/ftlabs/fastclick
  2. 在网页加在后执行 FastClick.attach(document.body);
  3. 没有了, 尽情享受手机端快速相应的体验吧

git服务器搭建

NetBeans中Git操作相关问题

netbeans中git推送代码报错

错误代码: cannot open git-receive-pack
解决方法:
.git/config文件中添加一下配置项, 然后保存, 然后推送就正常了, 代码的意思是 让Git忽略SSL证书错误

  1. [http]
  2. sslVerify = false

php调用系统shell命令自动更新线上网站代码为git版本库最新版

我们开发网站经常使用git最为代码版本库管理功能, git可以方便多人合作和代码历史记录的保存, 很方便, 于是有很多人就直接把git版本库的代码直接部署到线上, 每次更新就用git pull 去更新网站的代码, 只是每次更新代码都需要ssh到服务器上, 很麻烦, 想到php可以执行系统命令, 就想到了用网页更新线上代码, 具体往下看

准备

  1. 你的网站是php写的
  2. 你网站的代码使用的是git clone的代码, 更新代码使用的是git pull方式

自动更新php文件

1 . 在网站根目录下新建 /update.php, 并写入下面的代码, 可以把DIR修改成网站所在目录, 如果是当前目录, 可以不修改.

  1. <?php
  2. chdir(__DIR__);
  3. echo '<pre>';
  4. echo shell_exec('/usr/bin/git pull 2>&1');

2 . 然后修改网站目录中的文件所有文件的权限为 0777
3 . 把 .git/config 文件的远程提交地址中加上帐号信息 https://username:password@git.xxx.com/xxxxx
4 . 然后就可以访问 http://xxx.com/update.php 来更新网站代码了

注意: 如果你的网站根目录是源码根目录, 要禁止http访问.git目录, 因为这里保存了你的git帐号

php-angular模板引擎

源码地址: https://github.com/php-angular/php-angular

仿angularjs的php模板引擎

目前实现了一下几种标签和用法

标签

  1. php-if
  2. php-for
  3. php-foreach
  4. php-repeat
  5. php-show
  6. php-hide
  7. php-include
  8. php-init
  9. php-exec

变量输出
{$var}
{$array.name}
{$array[‘name’]}
{:func()}
{$var ? ‘’ : ‘’}

结合框架使用

具体的框架驱动可以在 /drivers 目录中找到

直接使用方法 /test/index.php

  1. <?php
  2. require '../lib/angular.php';
  3. // 配置
  4. $config = array(
  5. 'tpl_path' => './view/',
  6. 'tpl_suffix' => '.html',
  7. 'cache_path' => './cache/',
  8. 'attr' => 'php-',
  9. 'debug' => true,
  10. );
  11. // 实例化
  12. $view = new Angular($config);
  13. // 数据
  14. $data = array(
  15. 'title' => 'Hello PHP Angular',
  16. 'list' => array(
  17. array('name' => 'name_1', 'email' => 'email_1@qq.com'),
  18. array('name' => 'name_2', 'email' => 'email_2@qq.com'),
  19. array('name' => 'name_3', 'email' => 'email_3@qq.com'),
  20. array('name' => 'name_4', 'email' => 'email_4@qq.com'),
  21. array('name' => 'name_5', 'email' => 'email_5@qq.com'),
  22. ),
  23. );
  24. // 向模板引擎设置数据
  25. $view->assign($data);
  26. // 输出解析结果
  27. $view->display('index');
  28. // 获取输出结果
  29. // $view->fetch('index');

模板实例 /test/view/index.html

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>php-angular</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <style type="text/css">
  8. .box {
  9. padding: 10px;
  10. font-size: 12px;
  11. margin: 10px 5px;
  12. background: #CCC;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <div class="box" php-show="$title">{$title}</div>
  18. <div class="box" php-hide="$title">如果title的值为空, 则可以显示这条消息, 否则不显示</div>
  19. <div class="box">
  20. <span>foreach by [1,2,3,4,5]</span>
  21. <ul>
  22. <li php-foreach="[1,2,3,4,5] as $i">foreach {$i}</li>
  23. </ul>
  24. </div>
  25. <div class="box">
  26. <span>repeat by [1,2,3,4,5]</span>
  27. <ul>
  28. <li php-repeat="[1,2,3,4,5] as $i">foreach {$i}</li>
  29. </ul>
  30. </div>
  31. <div class="box" php-show="$list">
  32. <span>foreach by $list as $item</span>
  33. <ul>
  34. <li php-foreach="$list as $item">name:{$item.name} -- email: {$item.email}</li>
  35. </ul>
  36. </div>
  37. <div class="box" php-show="$list">
  38. <span>repeat by $list as $item</span>
  39. <ul>
  40. <li php-repeat="$list as $item">name:{$item.name} -- email: {$item.email}</li>
  41. </ul>
  42. </div>
  43. <div class="box" php-if="$list">
  44. <span>foreach by $list as $key => $item</span>
  45. <ul>
  46. <li php-foreach="$list as $key => $item">{$key} -- name:{$item.name} -- email: {$item.email}</li>
  47. </ul>
  48. </div>
  49. <div class="box">
  50. <span>for by ($i = 1; $i <= 10; $i++;)</span>
  51. <ul>
  52. <li php-for="$i = 1; $i <= 10; $i++">for {$i}</li>
  53. </ul>
  54. </div>
  55. <div class="box" php-if="$list">
  56. <span>$list 不为空</span>
  57. </div>
  58. </body>
  59. </html>

解析结果 /test/cache/6a992d5529f459a44fee58c733255e86.php

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>php-angular</title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <style type="text/css">
  8. .box {
  9. padding: 10px;
  10. font-size: 12px;
  11. margin: 10px 5px;
  12. background: #CCC;
  13. }
  14. </style>
  15. </head>
  16. <body>
  17. <?php if ($title) { ?><div class="box" ><?php echo $title; ?></div><?php } ?>
  18. <?php if (!($title)) { ?><div class="box" >如果title的值为空, 则可以显示这条消息, 否则不显示</div><?php } ?>
  19. <div class="box">
  20. <span>foreach by [1,2,3,4,5]</span>
  21. <ul>
  22. <?php foreach ([1,2,3,4,5] as $i) { ?><li >foreach <?php echo $i; ?></li><?php } ?>
  23. </ul>
  24. </div>
  25. <div class="box">
  26. <span>repeat by [1,2,3,4,5]</span>
  27. <ul>
  28. <?php foreach ([1,2,3,4,5] as $i) { ?><li >foreach <?php echo $i; ?></li><?php } ?>
  29. </ul>
  30. </div>
  31. <?php if ($list) { ?><div class="box" >
  32. <span>foreach by $list as $item</span>
  33. <ul>
  34. <?php foreach ($list as $item) { ?><li >name:<?php echo $item["name"]; ?> -- email: <?php echo $item["email"]; ?></li><?php } ?>
  35. </ul>
  36. </div><?php } ?>
  37. <?php if ($list) { ?><div class="box" >
  38. <span>repeat by $list as $item</span>
  39. <ul>
  40. <?php foreach ($list as $item) { ?><li >name:<?php echo $item["name"]; ?> -- email: <?php echo $item["email"]; ?></li><?php } ?>
  41. </ul>
  42. </div><?php } ?>
  43. <?php if ($list) { ?><div class="box" >
  44. <span>foreach by $list as $key => $item</span>
  45. <ul>
  46. <?php foreach ($list as $key => $item) { ?><li ><?php echo $key; ?> -- name:<?php echo $item["name"]; ?> -- email: <?php echo $item["email"]; ?></li><?php } ?>
  47. </ul>
  48. </div><?php } ?>
  49. <div class="box">
  50. <span>for by ($i = 1; $i <= 10; $i++;)</span>
  51. <ul>
  52. <?php for ($i = 1; $i <= 10; $i++) { ?><li >for <?php echo $i; ?></li><?php } ?>
  53. </ul>
  54. </div>
  55. <?php if ($list) { ?><div class="box" >
  56. <span>$list 不为空</span>
  57. </div><?php } ?>
  58. </body>
  59. </html>