0

I got now a two sides that contains numbers and between two specific numbers there is a string that shows a group of numbers, Let's say we got this 123456789$numbers1234567 and I want to get the result of $numbers so how can I get it? Thanks

AFB
  • 550
  • 2
  • 8
  • 25
  • 1
    try this one http://stackoverflow.com/questions/10949029/how-can-i-get-string-between-two-characters-string-php – Onel Sarmiento Jul 13 '13 at 03:35
  • what happens if $numbers is the same as the first group of numbers or the last? eg: `$numbers = 1234567` so you'll be looking in `12345678912345671234567` – kennypu Jul 13 '13 at 03:42
  • @kennypu Ok is there another way to get the characters after a Specific number? – AFB Jul 13 '13 at 03:52
  • that was just a question. if you're just using seperators, it would make more sense to just use something other than numbers. eg. `[num]$numbers[num], or |$numbers|` – kennypu Jul 13 '13 at 04:03
  • Welcome to Stack Overflow. We generally expect questions to show some research effort. Will you update your question to show what you have tried and explain how that attempt failed? – George Cummins Jul 13 '13 at 04:06

1 Answers1

0

If you know the two strings that it is sandwiched between then you can strip out the strings that you are looking for.

Not too elegant but this works:

$str1 = "123456789";
$str2 = "1234567";
$numberstr = "123456789";

$searchstring = "123456789".$numberstr."1234567";

$limit = 1;
$numbers = substr($searchstring, 0, strlen($searchstring) - strlen($str2)); // Remove the end of the string with length = $str2
$numbers = substr($numbers, strlen($numbers) - strlen($str1)); // Remove the most string from the beginning

print $numbers;

Output:

123456789

In summary, it removes the known string from the end, then the other known string from the beginning.

UPDATE: as per the comments, use two substrs to find the wanted string

immulatin
  • 2,118
  • 1
  • 12
  • 13