2020年11月12日 星期四

PHP的非貪婪模式修飾符和‌‌preg_match_all()

前言

正規式搜尋在第一個符合時終止(Regular expression to stop at first match)

非貪婪模式 - (.*?)

PHP Pattern Modifiers的 U (PCRE_UNGREEDY)

https://www.php.net/manual/en/reference.pcre.pattern.modifiers.php  Pattern Modifiers

https://stackoverflow.com/a/37347478  PHP preg_match and preg_match_all functions

找HTML字串tag標籤里的內容:

<b>example: </b><div align=left>this is a test</div>

preg_match_all(
    "|<[^>]+>(.*)</[^>]+>|U",
    "<b>example: </b><div align=left>this is a test</div>",
    $matches
);
‌2 => 會有2個結果

‌‌$matches
‌array (
  0 => 
  array (
    0 => '<b>example: </b>',
    1 => '<div align=left>this is a test</div>',
  ),
  1 => 
  array (
    0 => 'example: ',
    1 => 'this is a test',
  ),
)
U - PHP的非貪婪模式修飾符

$matches[1] is an array of strings matched by the first parenthesized sub-pattern

$matches[1] 是第一個帶刮號括號(())的子模式匹配的陣列 => (.*)

正則用“|”是避免“/”的衝突,或是正則中跳脫“/”

preg_match_all(
    "/<[^>]+>(.*)<\/[^>]+>/U",
    "<b>example: </b><div align=left>this is a test!</div>",
    $matches
);

不使用非貪婪修飾符U

preg_match_all(
    "/<[^>]+>(.*?)<\/[^>]+>/",
    "<b>example: </b><div align=left>this is a test!</div>",
    $matches
);

其他

preg_match_all("/\{([\w\d_]+)\}/", "?new_year={year}&new_month={month}&new_day={day}", $matches)
‌3

‌‌$matches
‌array (
  0 => 
  array (
    0 => '{year}',
    1 => '{month}',
    2 => '{day}',
  ),
  1 => 
  array (
    0 => 'year',
    1 => 'month',
    2 => 'day',
  ),
)



2020年10月28日 星期三

laravel 6 Mix前端指南

環境

框架:laravel 6.6

安裝 laravel/ui 

$ composer require laravel/ui:^1.0 --dev
如果報錯:

In PackageManifest.php line 122:

  Undefined index: name


Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Installation failed, reverting ./composer.json and ./composer.lock to their original content.
原因:composer 2.0的問題,把composer 版本回退之前版本
# composer self-update
Updating to version 2.0.2 (stable channel).
   Downloading (100%)
Use composer self-update --rollback to return to version 1.8.4
# composer self-update --rollback
Rolling back to version 2019-02-11_10-52-10-1.8.4.
ps.  laravel 6必須安裝 laravel/ui:^1.0 --dev 的版本


生成vue基本腳手架

$ php artisan ui vue
Vue scaffolding installed successfully.
Please run "npm install && npm run dev" to compile your fresh scaffolding.
這個操作新增了:
resources/js/components/ExampleComponent.vue
resources/sass/_variables.scss
resources/sass/app.scss
修改了:
package.json
resources/js/app.js
resources/js/bootstrap.js
註冊vue和vue組件
+++ b/resources/js/app.js
+window.Vue = require('vue');
...
+Vue.component('example-component', require('./components/ExampleComponent.vue').default);
...
+const app = new Vue({
+    el: '#app',
+});

$ npm install
$ npm run dev
...
 ERROR  Failed to compile with 2 errors

 error  in ./resources/sass/app.scss

Module build failed (from ./node_modules/css-loader/index.js):
ModuleBuildError: Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
ValidationError: Invalid options object. Sass Loader has been initialized using an options object that does not match the API schema.
 - options has an unknown property 'outputStyle'. These properties are valid:
   object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? }
    at validate (/var/www/html/project-z/coolapp/node_modules/schema-utils/dist/validate.js:98:11)
    at Object.loader (/var/www/html/project-z/coolapp/node_modules/sass-loader/dist/index.js:36:28)
    at /var/www/html/project-z/coolapp/node_modules/webpack/lib/NormalModule.js:316:20
    at /var/www/html/project-z/coolapp/node_modules/loader-runner/lib/LoaderRunner.js:367:11
    at /var/www/html/project-z/coolapp/node_modules/loader-runner/lib/LoaderRunner.js:233:18
    at runSyncOrAsync (/var/www/html/project-z/coolapp/node_modules/loader-runner/lib/LoaderRunner.js:143:3)
    at iterateNormalLoaders (/var/www/html/project-z/coolapp/node_modules/loader-runner/lib/LoaderRunner.js:232:2)
    at /var/www/html/project-z/coolapp/node_modules/loader-runner/lib/LoaderRunner.js:205:4
    at /var/www/html/project-z/coolapp/node_modules/enhanced-resolve/lib/CachedInputFileSystem.js:85:15
    at processTicksAndRejections (internal/process/task_queues.js:79:11)

 error  in ./resources/sass/app.scss

Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
ValidationError: Invalid options object. Sass Loader has been initialized using an options object that does not match the API schema.
 - options has an unknown property 'outputStyle'. These properties are valid:
   object { implementation?, sassOptions?, prependData?, sourceMap?, webpackImporter? }
    at validate (/var/www/html/project-z/coolapp/node_modules/schema-utils/dist/validate.js:98:11)
    at Object.loader (/var/www/html/project-z/coolapp/node_modules/sass-loader/dist/index.js:36:28)

 @ ./resources/sass/app.scss 2:14-253

原因:

 php artisan ui vue  改了 package.json ,使用了 "sass-loader": "^8.0.0", ,使得下一個操作 npm install 安裝了sass-loader 8.0.0

解法:

移除sass-loader 8.0.0 改裝7.1.0
$ npm uninstall --save-dev sass-loader
$ npm install --save-dev sass-loader@7.1.0

再執行
$ npm run dev

生成 登錄/註冊 腳手架

$ php artisan ui vue --auth
這個操作新增了:
app/Http/Controllers/HomeController.php
resources/views/auth/login.blade.php
resources/views/auth/passwords/confirm.blade.php
resources/views/auth/passwords/email.blade.php
resources/views/auth/passwords/reset.blade.php
resources/views/auth/register.blade.php
resources/views/auth/verify.blade.php
resources/views/home.blade.php
resources/views/layouts/app.blade.php
修改了:
routes/web.php

登錄頁

http://app.test:5566/login  使用users 表的 email 和password 登錄(passport API也是這個方式登錄的)

歡迎頁

http://app.test:5566/  resources/views/welcome.blade.php:68 上方新增了Login和Register按鈕

編寫Vue 組件

diff --git a/resources/js/components/ExampleComponent.vue b/resources/js/components/ExampleComponent.vue
index 3fb9f9aa..944c6973 100644
--- a/resources/js/components/ExampleComponent.vue
+++ b/resources/js/components/ExampleComponent.vue
@@ -3,7 +3,7 @@
         <div class="row justify-content-center">
             <div class="col-md-8">
                 <div class="card">
-                    <div class="card-header">Example Component</div>
+                    <div class="card-header">Example Component Bear</div>

                     <div class="card-body">
                         I'm an example component.
diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php
index 05dfca92..73075388 100644
--- a/resources/views/home.blade.php
+++ b/resources/views/home.blade.php
@@ -1,6 +1,7 @@
 @extends('layouts.app')

 @section('content')
+<example-component></example-component>
 <div class="container">
     <div class="row justify-content-center">
         <div class="col-md-8">

監視和自動重編譯發生變化的組件

在hyper-v 上執行,不要在windows 10 上執行,PHPStorm Deployment 要忽略 node_modules 目錄上傳
$ npm run watch-poll 

新增組件後,需要重新編譯 npm run dev , 或重新執行 npm run watch-poll  


參考資料

https://stackoverflow.com/a/61197256  Laravel PackageManifest.php: Undefined index: name
https://stackoverflow.com/a/60513876  Sass Loader Error: Invalid options object that does not match the API schema







2020年10月21日 星期三

使用Wireshark手機(Android+iPhone)抓包,免root

設備:

筆電(Windows 10) + iPhone 手機一隻 + Android 手機一隻

Windows 10

windows 先連上wifi

打開【網路連線】

設定 => 網路和網際網路 => Wi-Fi => 相關設定:更變界面卡選項

打開【行動熱點】

設定 => 網路和網際網路 => 行動熱點 => 開啟

打開【行動熱點】後,【網路連線】裡面會多一個網卡



iPhone 和 Android也連上該windows 10 分享的熱點


Wireshark

選擇剛剛打開【行動熱點】後【網路連線】裡面新增的網卡

iPhone和Android打開瀏覽器,手機訪問 http://www.iplocationfinder.com/ 
wireshark 過濾器: http && http.host == "www.iplocationfinder.com" 
即可看到iPhone(192.168.137.43)和Android(192.168.137.232)訪問 www.iplocationfinder.com 的封包







參考資料:

https://www.itread01.com/p/48468.html  手機抓包的兩種方法:wireshark抓包和fiddler抓包

2020年9月11日 星期五

不同git庫不同目錄同一個PHPStorm專案使用XDebug

開一個新空白專案

 File => New Project => PHP Empty Project

用ConEmu64 + Git Bash 到剛剛開的PHP專案下拉取不同專案
$ git clone git@github.com:kalecgos0616/project_index.git
$ git clone git@github.com:kalecgos0616/project_codes.git

配置SFTP

不同git不同目錄的code更新到伺服器不同路徑
C:\Users\PhpstormProjects\project_workspace\project_index => /var/www/html/project_index
C:\Users\PhpstormProjects\project_workspace\project_codes => /var/www/html/project_codes




配置XDebug

Open edit Run/Debug configurations dialog => Add New Configuration => PHP Remote Debug => 配置Server

Host 必須設 開發機上的vhost域名:example.com
配置本地和遠程對應的路徑
如果還是不能斷點,在開發機上對本機測試XDebug 端口有沒有通
# telnet 192.168.1.7 9000
Trying 192.168.1.7...
telnet: connect to address 192.168.1.7: Connection timed out
沒有通要用 Windows - CentOS 遠端XDebug調試PHP 的 2. 打開Windows的port 

結果

成功斷點


2020年4月30日 星期四

Photoshop 使用心得

打開尺標

檢視 => 尺標 ( ctrl + r )

單位改成像素px

https://zhidao.baidu.com/question/76698771  photoshop单位如何把像素改成厘米
編輯 => 偏好設定 => 單位和尺標

向上加大圖片大小

影像 => 版面尺寸 => 高度 = 高度 + xx px

把圖層放到下層

https://tw.answers.yahoo.com/question/index?qid=20110518000015KK04903  請問如何將圖片 移到最下層 (photoshop cs4)
右側開啟圖層面板 => 將圖層放到下面

測間距

切片工具 => 選取區域 => 右鍵 => 編輯切片選項














2020年4月25日 星期六

Windows 10 使用心得

IE 走SSR 代理

IE => 設定 => 進階 => 開啟Proxy設定 => 手動Proxy設定 => 使用Proxy設定「開啟」 => 輸入本機位址和本地SSR 監聽端口
Microsoft Store 和Skype 都會吃到這個設定



在github issues留言時插入code

如果要插入css,使用三個 ` 包起來,前面聲明css


```css
@font-face {  
  ...  
  src: url("assets/vant-icon-db1de1.woff2") format('woff2')  
}
```
s
結果是: