Here is one of the codes I would like to share if you are having some problems with removing specific strings from a text. Lets take a simple example. In this example we will be looking at the string “duration:0min32sec end 2023-10-11 04:12:57”, how can we capture the date and time from the string. We will be using two syntax to do it. strpos() and substr(). The ‘strpos()’ will calculate the position and substr() will remove all unnecessary first few characters while maintaining the balance character.
// The PHP code
$str = "duration:0min32sec end 2023-10-11 04:12:57";
$position = strpos($str,'end')+4;
$result = substr($str,$position);
echo $result;
Result obtained will be
2023-10-11 04:12:57
PHP CLASS IN PENANG
Are you looking to learn PHP from the best software developer in Penang? Why not reach us immediately so that we can assist you. We do provide customized php classes for college students.