How to remove everything before a specific first character?

Table of Contents

Sometime developers are facing the issue of eliminating all characters before the first specific character. Here I am describing how you can remove all the characters before a specific thing.

Just suppose we have a string as below:-

<?php
    $str = 'http://blog.phpmypassion.com'; 
?>

Now If I want to get my main domain then I have to follow below code..

<?php
if(($pos = strpos($str, '.')) !== false)
{
   $new_str = substr($str, $pos + 1);
}
else
{
   $new_str = get_last_word($str);
}
echo 'new string will be='.$new_str;
?>

Output:-

So the output will be “new string will be=phpmypassion.com”

It is a easiest way to remove everything before a specific characters position.

Check Video:-

Related posts