Forum Moderators: coopster
Filtering text to get specific digit
Hi,
I am trying to obtain a single digit from the value of the variable $resultD. The variable $resultD has an output with the following format:
$ccresult = 0 $ccstatus = '(3100)InvalidCreditCardNumber'
I need to get the digit right after “$ccresult =”; in this case the digit is “0”. How can I get the “0” and assign it to a new variable called “$resultnumber”?
Any help would be appreciated.
thx
[us4.php.net...]
Are the following two assumptions true:
1. The string always has the exact same number of characters before the digit?
2. You are doing this a lot in your script?
If so, using regex will incur more overhead than a built-in string function like substr [us2.php.net].
PS, the 888 doesn't have anything to do with the Penfield Mood Organ does it?
"At the Penfield mood organ, Iran Deckard sat with her right index
finger touching the numbered dial... If Rick were here, she thought,
he'd get me to dial 3 and that way I'd find myself wanting to dial
something important, ebullient joy or if not that then possibly an 888, the desire to watch TV no matter what's on it."
-- Philip K. Dick, "Do Androids Dream of Electric Sheep"
Tom
One way to do it is to do something like:
$resultnumber = $resultD{12}; // Where 12 is the character number in the string starting at 0. Strings, like arrays, are indexed from 0.
On the other hand, if it works and you aren't concerned about the speed penalty of regular expressions, your method should be fine.