【问题标题】:I want to remove things after .com我想删除 .com 之后的内容
【发布时间】:2015-05-30 23:59:42
【问题描述】:

您好,我找到了删除 www https 的方法,但现在我需要删除 ".com" 之后的任何内容 www.something.com/something/something 我想删除 */something/something~从网址。

<form method="post" action="">
    <label>URL adresa:</label><input type="text" placeholder= "URL" name="url" required /><br>
    <label>Titulek odkazu:</label><input type="text" placeholder= "Titulek" name="titulek" required/><br>
    <label>Otevření nového okna ANO</label><input type="checkbox" name="choice1" /><br>
    <label>Barva odkazu:</label><input type="color" name="color" /><br>
    <input type="submit" name="submit" />
</form>
<?php 
    $zakaz = array('www.', 'https://', 'http://' );
    if(isset($_POST['url']) AND isset($_POST['titulek']) AND isset($_POST['color']) AND !isset($_POST['choice1'])){
        $url = $_POST['url'];
        $titulek = $_POST['titulek'];
        $color = $_POST['color'];
        echo "<a href='" . $url . "'title ='" . $titulek . "'style=' color:" . $color . "; text-decoration: none ;'>" . str_replace($zakaz, '', $url) . "</a>"; 
    }elseif(isset($_POST['url']) AND isset($_POST['titulek']) AND isset($_POST['color']) AND isset($_POST['choice1'])){
        $url = $_POST['url'];
        $titulek = $_POST['titulek'];
        $color = $_POST['color'];
        echo "<a href='" . $url . "'title ='" . $titulek . "' target= '_blank' style=' color:" . $color . "; text-decoration: none ;'>" . str_replace($zakaz,'',$url ) . "</a>";    
    }
?>

【问题讨论】:

  • parse_url() 不要重新发明轮子
  • @Dagon 只有 Fred Flintstone 可以做到这一点。他摇滚
  • @Fred-ii- 他和 Wilma - 美国电视上出现的第一对已婚夫妻。
  • @Dagon 他们应该展示 Betty;她比威尔玛性感多了。我很喜欢深色的黑发。
  • 这很有趣,但请删除 cmets 上的 cmets :)

标签: php html forms if-statement replace


【解决方案1】:

你可以使用PHP的explode()

你可以使用:

$website = explode("/",$fullwebsite)[0]; //something.com

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-10-16
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 2021-02-13
    • 2019-07-21
    • 2019-07-25
    • 1970-01-01
    相关资源
    最近更新 更多