Finding value in text string

I have a text string and I need to find some text that appears after a certain value in that string:

Value that appears after "XXX: "

“Test 123 Hello XXX: 1 Test 555”;

So the value would be “1”

Any ideas?

Nice and vague. Lets try being a bit more specific.

What parts of this string change? Is there always a colon? Are there always 4 pieces of the string before the value you want? Is the XXX literal, or a value, or…?

Regular expressions would be the way to go, but without more information it could be done with string manipulation.

Use strpos and substr, simple. Hint: Use substr’s offset argument.

Hy,
Maybe this code is good:


$regexp = '/[a-z0-9_]+: ([0-9]+)/i';
$str = "Test 123 Hello XXX: 1 Test 555";

if (preg_match($regexp, $str, $mt)) {
  echo $mt[1];
}