Find string, then find string in-between chars

2472 views php

I'm having a hard time with this....

So, I have a load of text:


Now, what I am trying to do is search for betfair_affiliate_id";s:3: within that bulk of text and then display the text between the speech marks.

I was trying

        $betfred_show = 'betfair_affiliate_id";s:3:"';
        $betfred_show_value = substr($string, strpos($string, $betfred_show) + strlen($betfred_show), 3);

which does work, it brings back 888... but it's not really future proof as this just gets the 3 next digits. However, these could change to 4 or 5 digits.

Any suggestions?

answered question

What is the source of your data? It vaguely resembles JSON, but not quite.

@TimBiegeleisen it is serialised data (native to PHP). In this case it is a serialised array

This looks like a php serialized array... Doesn't it make much more sense to deserialize it and use the actual array elements instead of performing string operations on the serialized binary data?

1 Answer


It is a serialised array. You can simply unserialize it and access the key

$array = unserialize($input);
$output = $array['betfair_affiliate_id'];

posted this

Have an answer?


Please login first before posting an answer.