I need to extract a substring from another string using php.
$string = 'This is my string that conteined a Code:XYZ123';
$code = substr($text, -1, strpos($string,'Code:'));
echo $code ; // return 3
I need the whole code for example XYZ123
Try this code :
$string = 'This is my string that conteined a Code:XYZ123';
$code = substr($string ,strpos($string,'Code:'));
echo $code;
Make sure this is helpful to you.
Code:XYZ123