0

I would like to take this data:

questionX

Where X is any number from zero to infinity.

And subtract the text question from the field, and save just the number.

I was toying with substr($data, 0, 8) but haven't gotten it to work right, can somebody please give me a suggestion? Thanks so much.

Shackrock
  • 4,601
  • 10
  • 48
  • 74
  • `substr($data, 0, -1);` <-- will give you everything short of the last character in the `$data` string. But you already knew that from reading the relevant manual entry, didn't you? –  Jul 10 '12 at 19:05

2 Answers2

2

The manual for substring http://php.net/manual/en/function.substr.php indicates that the function takes three arguments: the string, the start, and the length. Length is optional. If omitted, substr will return the rest of the string starting from 'start'. One way to get your X value would be to do something like this:

$theNumber = substr($data, 8);

It look like you don't' really understand what substr does. Substr does not 'subtract' part of the string from itself. It returns the part of the string that you specify with the start and length paramaters

dykeag
  • 554
  • 3
  • 11
1

Try this

$number = str_replace("question", "", $string);
Zoltan Toth
  • 46,981
  • 12
  • 120
  • 134