c.k
c.k

Reputation: 1105

Remove a string php

I have this value: [email protected]|d76c3c301eb754c62b981f7208158a9f Best approach to remove all the string from the beginning of the word until the |. The | is the key here , on where to end. The output should be d76c3c301eb754c62b981f7208158a9f.

Upvotes: 1

Views: 66

Answers (6)

Lucas Gervas
Lucas Gervas

Reputation: 379

Use php explode($delimiter,$yourstring) function

$str="[email protected]|d76c3c301eb754c62b981f7208158a9f";
$exploded_str_array=explode('|', $str);
echo $required_str=$exploded_str_array[1];

//this contains the second part of the string delimited by | php manual for the explode function

Upvotes: 1

postrel
postrel

Reputation: 134

Split your string by using explode(). Then return the last element of the array using end()

 end(explode('|', '[email protected]|d76c3c301eb754c62b981f7208158a9f'));

Upvotes: 2

RomanPerekhrest
RomanPerekhrest

Reputation: 92894

Another short solution using substr and strpos functions:

$str = "[email protected]|d76c3c301eb754c62b981f7208158a9f";
$result = substr($str, strpos($str, "|") + 1); // contains "d76c3c301eb754c62b981f7208158a9f"

Upvotes: 2

Saty
Saty

Reputation: 22532

Use stristr()

$str="[email protected]|d76c3c301eb754c62b981f7208158a9f";
echo ltrim(stristr($str, '|'),"|"); 

Upvotes: 2

Niklesh Raut
Niklesh Raut

Reputation: 34924

Use explode

explode("|","[email protected]|d76c3c301eb754c62b981f7208158a9f")[1];

check this : https://eval.in/591968

Upvotes: 2

Jignesh Patel
Jignesh Patel

Reputation: 1022

Try below code

substr( strstr('[email protected]|d76c3c301eb754c62b981f7208158a9f', '|'), 1);

Upvotes: 1

Related Questions