我想删除.com之后的东西

时间:2015-03-26 19:42:25

标签: php html forms if-statement replace

您好我找到了一种删除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>";    
    }
?>

1 个答案:

答案 0 :(得分:0)

您可以使用PHP的explode()

您可以使用:

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