take numbers into separate variables | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

take numbers into separate variables

I have a little php script to telnet an adsl modem, i send a consult and the modem respond is something like this: wan adsl chandata far near-end interleaved channel bit rate: 4864 kbps near-end fast channel bit rate: 0 kbps far-end interleaved channel bit rate: 957 kbps far-end fast channel bit rate: 0 kbps so, i want to take only the "4864" - "957" values and store them into separate variables, can anyone help me with this? Thanks in advance.

4th Nov 2018, 9:50 PM
Tadeo Briceño
Tadeo Briceño - avatar
1 Answer
+ 2
So you basically need to separate the numbers from the text that is returned in the response? Sounds like some Regular Expressions could come in handy for this. Depending on PHP's RegEx engine, it might look something like this: regexobject = /[0-9]*/ [0-9] means a character that is zero through nine * the star after means a character zero to 9 that occurs zero or more times the / / may not be the correct way to do it for PHP, but I would look up how to do it for PHP. Search for "PHP regular expression". You'll probably want to use a function that returns the matched string, then convert the string to an integer, if you need to use it as an integer.
5th Nov 2018, 1:04 AM
Zeke Williams
Zeke Williams - avatar