Soptareanu Alex Soptareanu Alex - 20 days ago 5
PHP Question

Extract substring from string using php

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

Answer

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.