sg552
sg552

Reputation: 1543

Remove dot after TLD

I have this code and I need to remove dot (.) only after TLD

<?php
$url ='15rm-mo.hello.com.';

    $response = preg_replace('/[^A-Za-z1-9-]/', '', $url);
    echo $response;

?>

here is the output: 15rm-mohellocom

What I need is this: 15rm-mohello.com removing dot at the end. I can add dot in the regex but both dot will be remove. Any idea? Thanks in advance.

Upvotes: 0

Views: 530

Answers (2)

Cheery
Cheery

Reputation: 16214

echo rtrim('15rm-mo.hello.com.', '.');

ps: "15rm-mohello.com removing dot at the end." so, just at the end or in the middle too?

Upvotes: 7

Felix Yan
Felix Yan

Reputation: 15269

You may just replace something like \.$ with '', this will remove ANY . at end of giving string.

Upvotes: 3

Related Questions