RZ-Huang
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # PHP 相關語法與實際使用的場合例子 ###### tags: `php`、`application`、`note` ### 撈取最新一筆新增的資料 ` $sql = "SELECT * FROM table名稱 ORDER BY column名稱 DESC LIMIT 1"` ----- ### die() 與 exit() 差別 可以說是一樣啦,手冊說只是替換詞,但有網友說還是有一點點的差異或是語意不同。 下面那篇有人說,`exit()`是確保下面的程式都不執行;`die()`則是通常設定在如果失敗就`die()`,那就沒辦法再繼續執行下面的程式,有直接死在這行的那種語意。 #### 參考資料 1. [What are the differences in die() and exit() in PHP?](https://stackoverflow.com/questions/1795025/what-are-the-differences-in-die-and-exit-in-php) ----- ### 使用 HTTP GET 或 POST 以外的方法傳遞資料,後端如何接這個資料 可以這麼使用: ``` parse_str(file_get_contents('php://input'), $delete_vars); $id = $delete_vars['itemId']; ``` 其中 `parse_str()` 是把 `file_get_contents('php://input')` 傳進來的資料轉成陣列的資料型態,後端才可以去操作傳進來的資料。 `$delete_vars` 則是一個接收轉換形式後的資料的變數,可以任意取其名字。 `'itemId` 則是從 request 端傳進來的資料的變數名稱。 以上是簡略介紹,詳細的用法還要再研究與更新。 #### 參考資料 1. [HTTP protocol's PUT and DELETE and their usage in PHP](https://stackoverflow.com/questions/27941207/http-protocols-put-and-delete-and-their-usage-in-php) 2. [REST Webservice: PUT & Delete methods](https://www.sitepoint.com/community/t/rest-webservice-put-delete-methods/38060) ----- ### 判定字串中有無包含選定的字串 & 表示出 boolean ``` $str = 'sdwe'; echo var_export(strpos($str, 'id')); ``` `strpos(待測字串, 選定的字串)` 這個內建函式可以判定字串中有無選定的字串,像上方的例子,`$str` 變數的值是 `'sdwe'` ,所以是沒有包含 `'id'` 字串的,因此會回傳 `false`,假如有包含,那就會回傳待測字串和選定的字串第一個相符的字元(這個例子是 `'i'`)在待測字串中的位置的數字。 另外 `var_export()` 可以以字串顯示 PHP 的布林值,因為 PHP 預設不會顯示實際布林的值,`true` 顯示是 `1`;`false` 顯示是空的(有待確認)。 #### 參考資料 1. [php - 判斷字串是否存在](https://blog.xuite.net/choubee/blog/33638574-php+-+%E5%88%A4%E6%96%B7%E5%AD%97%E4%B8%B2%E6%98%AF%E5%90%A6%E5%AD%98%E5%9C%A8) 2. [PHP strpos() 函数](https://www.w3school.com.cn/php/func_string_strpos.asp) 3. [PHP - Get bool to echo false when false](https://stackoverflow.com/questions/4948663/php-get-bool-to-echo-false-when-false) ------ ### 判定是否為數字 使用 `is_numeric(value)` 可以判定 `value` 是否為數字或者是數字型式的字串,如果是,則會回傳 `true`。 #### 參考資料 1. [How to Use the PHP Is_Numeric() Function](https://www.thoughtco.com/isnumeric-php-function-2694075) ----- ### 計算後的小數點不精確 ```php= <?php $a = 60.200 + 89.700; $b = 150; echo $b - $a; ?> ``` 像上面的 `echo` 結果會是 `0.099999999999994`,而不是預期的 `0.1`,主要原因為 PHP 小數點的處理是使用分數來進行,1/2、1/4、1/8 以此類推。 若要達到精確的結果可以使用 `number_format()` 的內建函式: ```PHP= echo number_format( $b - $a, 3); // 0.100 ``` 第一個參數是要做轉換的參數,第二個參數是小數點要留幾位,`3` 就是小數點三位:`0.100`,如果想要消除小數點後面多餘的 0,可以在 `number_format()` 前面加 `(float)`,像這樣: ```PHP= echo (float)number_format( $b - $a, 3); // 0.1 ``` #### 參考資料 1. [number_format](https://www.php.net/manual/en/function.number-format.php) 2. [小數點不準](http://phorum.study-area.org/index.php?topic=50932.0) ## 一些數學式 * 無條件捨去:ceil($n) * 四捨五入:round($n) * 無條件捨去:floor($n) * 把變數轉成整數:intval($n) * 可以產生亂數的字串:uniqid()

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully