fightstarr20
fightstarr20

Reputation: 12598

PHP return character after value in string

I have a dynamic string that looks like this...

/tester?bc=7&tester=orange

Using PHP I am trying to return the single value after bc=

I have looked at strrchr but that doesn't seem to let me specify just returning one character, how should I be doing this?

Upvotes: 1

Views: 111

Answers (1)

Alexander Mikhalchenko
Alexander Mikhalchenko

Reputation: 4565

If the value is not from the request, you might want to use something like this:

$parsed = parse_url('/tester?bc=7&tester=orange');
parse_str($parsed['query'], $query);

The $query would contain this:

array(2) {
  ["bc"]=>
  string(1) "7"
  ["tester"]=>
  string(5) "orange"
}

Please mind that max_input_vars directive affects parse_str, so if your string would be extremely large, it might cut some parts.

Best regards, Alexander

Upvotes: 4

Related Questions