Split Numbers From String Using Php

by Mohan 2013-03-26 15:05:41



<h2><font color=#0000B3>Split Numbers From String Using Php</font></h2>


To split numbers present at last of a string and increment the number by 1 using php


$vname="words9999";
echo "Initial value==".$vname;
$i = 1;
$strln=strlen($vname);
for($j=0;$j<=$strln;$j++)
{
$nm=substr($vname,-$j);
if (!preg_match('/[^0-9]/', $nm))
{
$vnameapp=$nm;
}

}
$vnam=explode($vnameapp,$vname);
$vnameapp++;
$vname=$vnam[0].$vnameapp;
echo "<br>The final value of vname=".$vname;


The output will be

<font color=#000080>Initial value==words9999

The final value of vname=words10000</font>
831
like
0
dislike
0
mail
flag

You must LOGIN to add comments