Wednesday, January 18, 2017

anil

How to remove everything before a specific first character?


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:-




About Author -

Hi, I am Anil.

Welcome to my eponymous blog! I am passionate about web programming. Here you will find a huge information on web development, web design, PHP, Python, Digital Marketing and Latest technology.

Subscribe to this Blog via Email :

Note: Only a member of this blog may post a comment.