Search code examples
phptrim

Issue with PHP trim() - removing "https://" from the string, a strange issue


I'm using PHP trim() to remove https:// from a sting.

trim('https://www.hakanerenler.net', 'https://')

If i write .com to the domain, its working fine. But if its a .net domain, the last T dissapear. Why sould if the trimming the last "T" of .net

echo  trim('https://www.hakanerenler.com', 'https://');
    returns "www.hakanerenler.com"

echo  trim('https://www.hakanerenler.net', 'https://');
returns "www.hakanerenler.ne"

Thanks


Solution

  • The trim function removes any of the supplied characters, not literal matches. Since .net contains a t is removing it.

    You should use str_replace() instead. For more advanced manipulations you could consider parse_url()