$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 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); ?> 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! 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. 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,. 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
Archived
This topic is now archived and is closed to further replies.