Solved

help with substr

Posted on 2008-06-17
4
238 Views
Last Modified: 2010-04-21
Hi

I'm trying to work on a check digit routine and need to do 3 things
1) find the length of the variable $paymentReference1
2) set the variable $_toCheck to be all the digits except the last one
3) set the variable $_toMatch to be the last digit

Not sure if the code I have attached is the best way to do this or could it be simpler. Will my code even work?

Neil
$paymentReference1 = "10948055";
 

$_len = strlen($paymentReference1)-1;

$_toCheck = substr($toCheck, 1, $_len);

$_toMatch = substr($toCheck, $_len, 1);

Open in new window

0
Comment
Question by:NeilT
  • 2
4 Comments
 
LVL 49

Expert Comment

by:Roonaan
ID: 21806993
Looks fine, 3) can be
$_toMatch = substr($toCheck, -1);
0
 
LVL 49

Expert Comment

by:Roonaan
ID: 21806996
Actually, 2 is incorrect. Should be
$_toCheck = substr($toCheck, 0, $_len);
0
 
LVL 48

Accepted Solution

by:
hernst42 earned 500 total points
ID: 21807007
Just try:

$toCheck = $paymentReference1;
$_toCheck = substr($toCheck, 0, -1);
$_toMatch = substr($toCheck, -1);
0
 
LVL 3

Author Closing Comment

by:NeilT
ID: 31468124
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now