Remove portion of a string after a certain character in php
×

How to remove portion of a string after a certain character in PHP?

23222

With the help of PHP substr() and strops() functions, we can remove the portion of a string after a certain character.

strpos():

It is an inbuilt function of PHP which searches a particular piece of text in a string and returns the first occurrence of that text.


substr():

It is also an inbuilt function of PHP which returns the part of a string by position.

We find the part of a string after a certain character with the help of above both functions.


Example:

?php
$string="coding-tag";
$position=strpos($string, "-");
$result=substr($string,intval($position)+1);
echo $result;
?

Output:




Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments