$username Posted November 23, 2009 Share Posted November 23, 2009 Hello All, So I am stuck and not sure what function would work best for my case. I have this value $strg = "test.example.com"; I want to remove the 'test.' from the string so that it is just 'example.com' I started to look at ltrim function. But I am not sure how I would read it from left to right till it got to the first '.'. $trimmed = ltrim("test.example.com", " '"*".'); If you have any help or a better way please let me know.. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/182680-removing-characters-to-a-cretin-character/ Share on other sites More sharing options...
sasa Posted November 23, 2009 Share Posted November 23, 2009 <?php $strg = "test.example.com"; echo $trimed = substr($strg, strpos($strg,'.')+1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/182680-removing-characters-to-a-cretin-character/#findComment-964182 Share on other sites More sharing options...
$username Posted November 23, 2009 Author Share Posted November 23, 2009 Damn that is awesome... I would have never got that +1 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/182680-removing-characters-to-a-cretin-character/#findComment-964191 Share on other sites More sharing options...
$username Posted November 23, 2009 Author Share Posted November 23, 2009 If I am am now looking to count the number of '.' and if there is only 1 I would bypass the $trimed = substr($strg, strpos($strg,'.')+1); How can I count the '.' in a string? Thanks, Currently looking in php docs. Quote Link to comment https://forums.phpfreaks.com/topic/182680-removing-characters-to-a-cretin-character/#findComment-964198 Share on other sites More sharing options...
$username Posted November 23, 2009 Author Share Posted November 23, 2009 Found it!! $str = '312.test.com'; echo substr_count($str, "."); This will return the number of times it is in the string,. Quote Link to comment https://forums.phpfreaks.com/topic/182680-removing-characters-to-a-cretin-character/#findComment-964217 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.