Syntax error Extract numbers after the last hyphen in PHP?

Extract numbers after the last hyphen in PHP?



Let’s say the following is our string including hyphen and numbers as well −

"John-45-98-78-7898906756"

To extract numbers after – i.e. hyphen, use the concept of explode() with parameters - and $yourVariableName.

The PHP code is as follows −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<?php
   $values = "John-45-98-78-7898906756";
   $values = explode("-",$values);
   $values = $values[4];
   echo $values;
?>
</body>
</html>

Output

7898906756
Updated on: 2020-11-20T05:36:38+05:30

856 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements