久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<i id='lV949'><tr id='lV949'><dt id='lV949'><q id='lV949'><span id='lV949'><b id='lV949'><form id='lV949'><ins id='lV949'></ins><ul id='lV949'></ul><sub id='lV949'></sub></form><legend id='lV949'></legend><bdo id='lV949'><pre id='lV949'><center id='lV949'></center></pre></bdo></b><th id='lV949'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='lV949'><tfoot id='lV949'></tfoot><dl id='lV949'><fieldset id='lV949'></fieldset></dl></div>
  1. <legend id='lV949'><style id='lV949'><dir id='lV949'><q id='lV949'></q></dir></style></legend>
  2. <small id='lV949'></small><noframes id='lV949'>

  3. <tfoot id='lV949'></tfoot>

      <bdo id='lV949'></bdo><ul id='lV949'></ul>

    1. 正則表達式有條件地用超鏈接替換 ??Twitter 標

      Regex to conditionally replace Twitter hashtags with hyperlinks(正則表達式有條件地用超鏈接替換 ??Twitter 標簽)
      • <i id='vMXjR'><tr id='vMXjR'><dt id='vMXjR'><q id='vMXjR'><span id='vMXjR'><b id='vMXjR'><form id='vMXjR'><ins id='vMXjR'></ins><ul id='vMXjR'></ul><sub id='vMXjR'></sub></form><legend id='vMXjR'></legend><bdo id='vMXjR'><pre id='vMXjR'><center id='vMXjR'></center></pre></bdo></b><th id='vMXjR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vMXjR'><tfoot id='vMXjR'></tfoot><dl id='vMXjR'><fieldset id='vMXjR'></fieldset></dl></div>
      • <tfoot id='vMXjR'></tfoot>
          <bdo id='vMXjR'></bdo><ul id='vMXjR'></ul>

                <legend id='vMXjR'><style id='vMXjR'><dir id='vMXjR'><q id='vMXjR'></q></dir></style></legend>

              • <small id='vMXjR'></small><noframes id='vMXjR'>

                  <tbody id='vMXjR'></tbody>
                本文介紹了正則表達式有條件地用超鏈接替換 ??Twitter 標簽的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在編寫一個小的 PHP 腳本,以從用戶提要中獲取最新的半打 Twitter 狀態更新,并將它們格式化以在網頁上顯示.作為其中的一部分,我需要一個正則表達式替換來將主題標簽重寫為 search.twitter.com 的超鏈接.最初我嘗試使用:

                (取自 https://gist.github.com/445729)

                在測試過程中,我發現 #test 被轉換為 Twitter 網站上的鏈接,但 #123 不是.在互聯網上進行了一些檢查并使用各種標簽后,我得出的結論是,主題標簽必須在某處包含字母字符或下劃線才能構成鏈接;僅包含數字字符的標簽將被忽略(大概是為了阻止諸如好的演示文稿鮑勃,幻燈片 #3 是我的最愛!"之類的鏈接).這使得上面的代碼不正確,因為它很樂意將#123 轉換為鏈接.

                我已經有一段時間沒有做太多正則表達式了,所以在我生疏的時候,我想出了以下 PHP 解決方案:

                 0) {foreach ($arrHashtags[2] as $strHashtag) {//檢查每個標簽,看看某處是否有字母或下劃線if (preg_match('/#d*[a-z_]+/i', $strHashtag)) {$test = str_replace($strHashtag, '<a .substr($strHashtag, 1).'">'.$strHashtag.'</a>', $test);}}}回聲 $test;?>

                它有效;但它的作用似乎相當冗長.我的問題是,是否有一個類似于我從 gist.github 獲得的 preg_replace 將有條件地將主題標簽重寫為超鏈接,前提是它們不只包含數字?

                解決方案

                (^|s)#(w*[a-zA-Z_]+w*)

                PHP

                $strTweet = preg_replace('/(^|s)#(w*[a-zA-Z_]+w*)/', '1#<a , $strTweet);

                此正則表達式表示 # 后跟 0 個或多個字符 [a-zA-Z0-9_],后跟字母字符或下劃線(1 個或多個),然后是 0 個或多個單詞字符.

                http://rubular.com/r/opNX6qC4sG <- 在此處測試.>

                I'm writing a small PHP script to grab the latest half dozen Twitter status updates from a user feed and format them for display on a webpage. As part of this I need a regex replace to rewrite hashtags as hyperlinks to search.twitter.com. Initially I tried to use:

                <?php
                $strTweet = preg_replace('/(^|s)#(w+)/', '1#<a , $strTweet);
                ?>
                

                (taken from https://gist.github.com/445729)

                In the course of testing I discovered that #test is converted into a link on the Twitter website, however #123 is not. After a bit of checking on the internet and playing around with various tags I came to the conclusion that a hashtag must contain alphabetic characters or an underscore in it somewhere to constitute a link; tags with only numeric characters are ignored (presumably to stop things like "Good presentation Bob, slide #3 was my favourite!" from being linked). This makes the above code incorrect, as it will happily convert #123 into a link.

                I've not done much regex in a while, so in my rustyness I came up with the following PHP solution:

                <?php
                $test = 'This is a test tweet to see if #123 and #4 are not encoded but #test, #l33t and #8oo8s are.';
                
                // Get all hashtags out into an array
                if (preg_match_all('/(^|s)(#w+)/', $test, $arrHashtags) > 0) {
                  foreach ($arrHashtags[2] as $strHashtag) {
                    // Check each tag to see if there are letters or an underscore in there somewhere
                    if (preg_match('/#d*[a-z_]+/i', $strHashtag)) {
                      $test = str_replace($strHashtag, '<a .substr($strHashtag, 1).'">'.$strHashtag.'</a>', $test);
                    }
                  }
                }
                
                echo $test;
                ?>
                

                It works; but it seems fairly long-winded for what it does. My question is, is there a single preg_replace similar to the one I got from gist.github that will conditionally rewrite hashtags into hyperlinks ONLY if they DO NOT contain just numbers?

                解決方案

                (^|s)#(w*[a-zA-Z_]+w*)
                

                PHP

                $strTweet = preg_replace('/(^|s)#(w*[a-zA-Z_]+w*)/', '1#<a , $strTweet);
                

                This regular expression says a # followed by 0 or more characters [a-zA-Z0-9_], followed by an alphabetic character or an underscore (1 or more), followed by 0 or more word characters.

                http://rubular.com/r/opNX6qC4sG <- test it here.

                這篇關于正則表達式有條件地用超鏈接替換 ??Twitter 標簽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                PHP PDO ODBC connection(PHP PDO ODBC 連接)
                Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)

                • <bdo id='TGrto'></bdo><ul id='TGrto'></ul>
                  <i id='TGrto'><tr id='TGrto'><dt id='TGrto'><q id='TGrto'><span id='TGrto'><b id='TGrto'><form id='TGrto'><ins id='TGrto'></ins><ul id='TGrto'></ul><sub id='TGrto'></sub></form><legend id='TGrto'></legend><bdo id='TGrto'><pre id='TGrto'><center id='TGrto'></center></pre></bdo></b><th id='TGrto'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='TGrto'><tfoot id='TGrto'></tfoot><dl id='TGrto'><fieldset id='TGrto'></fieldset></dl></div>

                          <tbody id='TGrto'></tbody>
                      • <legend id='TGrto'><style id='TGrto'><dir id='TGrto'><q id='TGrto'></q></dir></style></legend>
                        <tfoot id='TGrto'></tfoot>

                          <small id='TGrto'></small><noframes id='TGrto'>

                          主站蜘蛛池模板: 欧美日韩精品一区二区天天拍 | 亚洲资源站 | 中文字幕在线观看视频一区 | 中文字幕一区二区三区在线乱码 | 99精品电影 | 免费毛片网 | 国产欧美在线播放 | 自拍偷拍亚洲一区 | 日韩在线视频免费观看 | 91精品国产91久久综合桃花 | 国产一级片一区二区三区 | 日韩欧美中文 | 国产日韩一区二区三区 | 欧美性一区二区三区 | 三级在线免费 | 日韩一级免费电影 | 精品国偷自产在线 | 亚洲福利网 | 麻豆av在线免费观看 | 久久国产婷婷国产香蕉 | 欧美日韩亚洲一区 | 亚洲综合字幕 | 91xxx在线观看 | 久久精品99久久 | 国产一区二区三区精品久久久 | 狠狠综合网 | 免费亚洲一区二区 | 日韩在线视频一区 | 一区二区三区中文字幕 | 中文字幕日本一区二区 | 美女视频黄色的 | 亚洲国产精品成人久久久 | 国产精品视频久久 | 国产激情偷乱视频一区二区三区 | 国产精品久久99 | 日韩不卡一区二区三区 | 日本中文字幕日韩精品免费 | 一区二区不卡视频 | 国内精品视频在线观看 | 欧美日韩成人在线 | 亚洲一区二区久久 |