HTML如果url存在导出为href链接

时间:2017-08-30 12:27:48

标签: html wordpress

我在wordpress网站上工作,而且我没有多少关于php的经验。在wordpress上,您可以输入网站的网址。我需要帮助创建一个if语句,好像一个url存在于wordpress上输入的url的链接。

当用户可以在不同的图标上输入网址时,它如何在wordpress中运行。如果他们这样做,图标需要像href一样可点击。

以下是代码:

<div id="legend">
    <div class="text-center">

    <p>As we continue to track performance and goal achievement, TBD spaces will be filled in with <br />content meant to support and react to continuing progress and opportunities.</p>
        <ul>
            <li class="oem-event"><span>OEM Event</span></li>
            <li class="fa-icon"><i class="fa fa-search" aria-hidden="true"></i> Research</li>
            <li class="fa-icon"><i class="fa fa-check-circle" aria-hidden="true"></i> Audit</li>
            <li class="fa-icon"><i class="fa fa-lightbulb-o" aria-hidden="true"></i> Planning</li>
            <li class="fa-icon"><i class="fa fa-car" aria-hidden="true"></i> Inventory</li>
            <li class="fa-icon"><i class="fa fa-commenting" aria-hidden="true"></i> Blog</li>
        </ul>
        <ul>
            <li class="fa-icon"><i class="fa fa-balance-scale" aria-hidden="true"></i> Comparison</li>
            <li class="fa-icon"><i class="fa fa-link" aria-hidden="true"></i> Sitelink</li>
            <li class="fa-icon"><i class="fa fa-window-maximize" aria-hidden="true"></i> Landing Page</li>
            <li class="fa-icon"><i class="fa fa-cog" aria-hidden="true"></i> Custom</li>
            <li class="fa-icon"><i class="fa fa-plus-circle" aria-hidden="true"></i> Social Post</li>
            <li class="fa-icon"><i class="fa fa-folder" aria-hidden="true"></i> Migration </li>
            <li class="fa-icon"><i class= "fa fa-font-awesome" aria-hidden="true"></i> Enhancement </li>
            <li class="fa-icon"><i class="fa fa-certificate" aria-hidden="true"></i> WOW </li>
            <li class="fa-icon"><i class= "fa fa-google" aria-hidden="true"></i>Google Post</li>
        </ul>
    </div>
</div>

到目前为止我已尝试过这个:

<?php

    // The Regular Expression filter
    $reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

    // The Text you want to filter for urls
    $text = "The text you want to filter goes here. http://google.com";

    // Check if there is a url in the text
    if(preg_match($reg_exUrl, $text, $url)) {

       // make the urls hyper links
       echo preg_replace($reg_exUrl, "<a href="{$url[0]}">{$url[0]}</a> ", $text);

    } else {

       // if no urls in the text just return the text
       echo $text;

    }
?> 

但是,我认为这不是我需要做的事情

0 个答案:

没有答案