99久久免费国产精品-天天爽夜夜爽夜夜爽-色噜噜久久综合伊人一本-国产无遮挡又黄又爽免费视频

首頁>> 開發技術知識>> 網站建站知識>>ASP.net 關健詞加鏈接


ASP.net 關健詞加鏈接

/// <summary> 
    /// 為關鍵詞加上超鏈接 
    /// </summary> 
    /// e.g.:  
    /// string result=GetInnertLink("<a href="http//www.baidu.com" mce_href="http/www.baidu.com">Ningxi</a>Xi過得<span>XI<span>好<a href="http://m.lidajijin.com" mce_href=
    /// <param name="htmlcode">要把關鍵詞加上超鏈接的html源文本</param> 
    /// <param name="keyword">將要加上超鏈接的關鍵詞</param> 
    /// <param name="title">將要加上的超鏈接的描文本</param> 
    /// <param name="url">將要加上的超鏈接的url地址</param> 
    /// <param name="target">將要加上的超鏈接的打開方式</param> 
    /// <param name="num">為html文本內的前num個關鍵詞加上超鏈接,0代表全加上超鏈接</param> 
    /// <returns>返回為關鍵詞加上超鏈接后的html文本</returns> 
    public static string GetInnertLink(string htmlcode, string keyword, string title, string url, string target, int num)
    {
        string htmlcodeResult = htmlcode;  //用于保存最新的html文本
        string htmlcodeLower = htmlcodeResult.ToLower();  //用于保存最新的Hmtl文本的小寫,方便不分大小寫找出關鍵詞
        string keywordResult = "";  //用于保存關鍵詞的原來面貌,可能是大寫,或者有大也有小
        int keyIndex = 0;           //關鍵詞所在位置
        int currentIndex = 0;       //每次搜索關鍵詞的開始位置
        int currentNum = 0;         //保存當前加上了多少個有效超鏈接
        int LBracketIndex = 0;      //左尖括號<位置
        int RBracketIndex = 0;      //右尖括號>位置
        if (num == 0)
        {
            num = htmlcode.Length;
        }
        while (currentIndex <= htmlcodeLower.Length && currentNum < num)
        {
            if (htmlcodeLower.IndexOf(keyword.ToLower(), currentIndex) > -1)
            {
                keyIndex = htmlcodeLower.IndexOf(keyword.ToLower(), currentIndex);
                LBracketIndex = keyIndex;
                do
                {
                    LBracketIndex = htmlcodeLower.LastIndexOf("<", LBracketIndex - 1, LBracketIndex - currentIndex);
                }
                while (LBracketIndex != -1 && htmlcodeLower.Substring(LBracketIndex + 1, 1) == "/");
                RBracketIndex = htmlcodeLower.LastIndexOf(">", keyIndex - 1, keyIndex - currentIndex);
                if (LBracketIndex <= RBracketIndex)
                {
                    //不在標簽的屬性內,可以有在標簽開始與結束標志內,或在開始與結束標志外 
                    LBracketIndex = htmlcodeLower.LastIndexOf("<", keyIndex - 1, keyIndex - currentIndex);
                    if (LBracketIndex != -1 && htmlcodeLower.Substring(LBracketIndex + 1, 1) != "/")
                    {
                        //在開始與結束標志內 
                        //關鍵詞在開始標簽與結束標簽內,要再判定是不是a標簽或pre標簽 
                        if (htmlcodeLower.Substring(LBracketIndex + 1, 1) == "a" || htmlcodeLower.Substring(LBracketIndex + 3, 3) == "pre")
                        {
                            //關鍵詞在開始與結束a標簽或pre標簽內,不可加超鏈接,循環再來 
                            currentIndex = keyIndex + keyword.Length;
                        }
                        else
                        {
                            //可以加超鏈接 
                            keywordResult = htmlcodeResult.Substring(keyIndex, keyword.Length);
                            htmlcodeResult = htmlcodeResult.Remove(keyIndex, keyword.Length);
                            htmlcodeResult = htmlcodeResult.Insert(keyIndex, "<a href=''" + url + "''  title=''" + title + "'' target=''" + target + "''>" + keywordResult + "</a>");
                            htmlcodeLower = htmlcodeResult.ToLower();
                            currentIndex = htmlcodeResult.IndexOf("</a>", keyIndex) + 4;
                            currentNum += 1;
                        }
                    }
                    else if ((RBracketIndex = htmlcodeLower.LastIndexOf(">", keyIndex - 1, keyIndex - currentIndex)) != -1)
                    {
                        //
                        // 當查找范圍內存在''>''標簽則說明在一個靜態控件中則需要判斷這個控件是否是a標簽
                        //
                        if (htmlcodeLower.Substring(htmlcodeLower.IndexOf(''<'', currentIndex) + 1, 2) == "/a")
                        {
                            //關鍵詞在a標簽內則不能添加超鏈接
                            currentIndex = keyIndex + keyword.Length;
                        }
                    }
                    else
                    {
                        //在結束標志外,可以加超鏈接 
                        keywordResult = htmlcodeResult.Substring(keyIndex, keyword.Length);
                        htmlcodeResult = htmlcodeResult.Remove(keyIndex, keyword.Length);
                        htmlcodeResult = htmlcodeResult.Insert(keyIndex, "<a href=''" + url + "'' title=''" + title + "'' target=''" + target + "''>" + keywordResult + "</a>");
                        htmlcodeLower = htmlcodeResult.ToLower();
                        currentIndex = htmlcodeResult.IndexOf("</a>", keyIndex) + 4;
                        currentNum += 1;
                    }
                }
                else
                {
                    //關鍵詞是標簽內的屬性值,不可加超鏈接,循環再來 
                    currentIndex = keyIndex + keyword.Length;
                }
            }
            else
            {
                currentIndex = htmlcodeLower.Length + 1;
            }
        }
        return htmlcodeResult;
    }

分享聯系我們

掃二維碼與項目經理溝通 我們在微信上24小時期待你的聲音

感謝您的關注分享“ASP.net 關健詞加鏈接”
煙寒網絡真誠為您服務 ,點擊客服直接咨詢下單.

我們服務

南寧網絡公司南寧網站建設

網站建設

高端網站建設服務商、相信品牌力量、相信知名企業;制作后收費13014982176!

南寧微信小程序/微信公眾號

微信小程序/微信公眾號

微信小程序 背靠10億流量,不論用戶需求是什么,都能被開發使用 一點創意,就能在“社交圈”中脫穎而出。

南寧網站優化/SEO

網站優化/SEO

讓您的網站更靠近排名位置,讓客戶更容易找到您,seo優化是一個漫長過程,整個網站營銷花最少的錢起最大的作用。

我們服務客戶


企業形象網站、個人博客、政府門戶網站、新聞傳媒網站最省錢、省時、省備案 建站快、效率高更多服務
廣西華崧集團網站品牌設計

廣西華崧集團網站品牌設計

廣西華崧林業發展集團(以下簡稱華崧集團)組建于2017年8月,集團總部位于廣西壯...

廣西大和平房地產有限公司

廣西大和平房地產有限公司

廣西鴻生源環保科技有限公司

廣西鴻生源環保科技有限公司

主站蜘蛛池模板: 久久久综合九色综合鬼色| 亚洲综合无码一区二区| 国产av一区二区三区最新精品| 麻豆av一区二区三区久久| 性一交一乱一乱一视频| 噜噜噜噜私人影院| 欧美xxxxx在线观看| 白又丰满大屁股bbbbb| 护士张开腿被奷日出白浆| 欧美老人与小伙子性生交| 小蜜被两老头吸奶头在线观看| 真人新婚之夜破苞第一次视频 | 久久久av波多野一区二区| 狠狠精品干练久久久无码中文字幕| 国产欧美精品一区二区色综合| 中文天堂资源在线www| 亚洲熟妇色xxxxx欧美老妇| 无码国产精品一区二区免费vr| 精品亚洲国产成人| 成年在线网站免费观看无广告| 久久香蕉国产线看观看猫咪av| 日韩午夜福利无码专区a| 黑人大荫道bbwbbb高潮潮喷| 国产av无码专区亚洲av琪琪| 最新国产精品无码| 人妻无码一区二区视频| 无码熟妇人妻av在线网站| 最近2019年好看中文字幕视频 | 国产亚洲精品成人aa片新蒲金| 闺蜜张开腿让我爽了一夜| 中文字幕精品久久久久人妻红杏1| 久激情内射婷内射蜜桃| 国产高潮刺激叫喊视频| 久久精品中文字幕| 免费观看mv大片高清| 日本三级香港三级三级人!妇久| 无码成人一区二区| 日韩精品久久久肉伦网站| 男人猛戳女人30分钟视频大全| 国产乱人伦av在线a| 国产精品美女久久久|