Walker33 Posted May 21, 2009 Share Posted May 21, 2009 I have a column that contains a string, for example, R01,R02,R03,R04,S01,S02,S03,A01,A02. I need to isolate the last R or S or A, which my code does, but then I need to add one to that final variable. ++ just repeats it. Is there a simple way to do this then to split up $result ? <?php $query6 = pg_query("SELECT sublicenses FROM sublicenses WHERE license = '3RF6EWOT2'"); $getarray = pg_fetch_assoc($query6); $license6 = $getarray['sublicenses']; echo "$license6 <br><br>"; $string="$license6"; $domain3=strrchr($string,"S"); echo "$domain3<br><br>"; if (!$domain3){echo "no licenses<br><br>";} $string2=split(",",$domain3); print_r ($string2); $result = $string2['0']; echo "<br><br>$result"; $addstn = $result++; echo "<br><br>$addstn"; ?> So my $result returns what I want, S03. But my $addstn also returns S03. I need a final return of S04, in this instance. Thanks a lot for any tips! Quote Link to comment Share on other sites More sharing options...
gevans Posted May 21, 2009 Share Posted May 21, 2009 I'm not sure if this will, work, but off the top of my head; <?php //This works if there are always 3 characters $number = (int) $result[2]; $new_number = $number+1; $result = srr_replace($number, $new_number, $result); echo $result; Quote Link to comment Share on other sites More sharing options...
Walker33 Posted May 21, 2009 Author Share Posted May 21, 2009 Hmm. Put it in just as you wrote it, but not getting a return for the echo. Quote Link to comment Share on other sites More sharing options...
Walker33 Posted May 21, 2009 Author Share Posted May 21, 2009 And yes, it will always be a three-digit variable, one letter, two numbers. Quote Link to comment Share on other sites More sharing options...
gevans Posted May 21, 2009 Share Posted May 21, 2009 little syntax error; $result = srr_replace($number, $new_number, $result); should be $result = str_replace($number, $new_number, $result); Quote Link to comment Share on other sites More sharing options...
Walker33 Posted May 21, 2009 Author Share Posted May 21, 2009 Beautiful! Works like a champ. Thank you very much. I'm pretty new to this, so I wasn't aware of the str_replace function. Really appreciate your help! Quote Link to comment Share on other sites More sharing options...
Walker33 Posted May 21, 2009 Author Share Posted May 21, 2009 Spoke a second too soon. If my result is R11, your script returns R22 instead of R12. Quote Link to comment Share on other sites More sharing options...
gevans Posted May 21, 2009 Share Posted May 21, 2009 Try this <?php $result = substr_replace($result, $new_number, 2); Quote Link to comment Share on other sites More sharing options...
Walker33 Posted May 21, 2009 Author Share Posted May 21, 2009 That's the ticket! This time I tested all dup numbers, 11, 22, 33, etc. Perfect. Thanks again, your help is greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.