Welcome Guest, Not a member yet? Register   Sign In
Split String and Number in PHP
#4

Best way is by using a regular expression.

Example:
PHP Code:
$str 'Johnson 54321';

if ( 
preg_match '/\D+([0-9]+)/'$str$matches ) )
{
 
   print_r($matches);

The pattern \D+([0-9]+) says: check for 1 or more non-digit characters first, followed by 1 or more digit characters.
The part that is between braces, will be returned in the $mathes array.

The result will be in $matches[1], which will be equal to '54321'.
Reply


Messages In This Thread
Split String and Number in PHP - by CharlesK - 03-02-2018, 02:42 AM
RE: Split String and Number in PHP - by PaulD - 03-02-2018, 04:31 AM
RE: Split String and Number in PHP - by CharlesK - 03-02-2018, 07:26 AM
RE: Split String and Number in PHP - by Wouter60 - 03-02-2018, 09:52 AM



Theme © iAndrew 2016 - Forum software by © MyBB