Encoded

Handle encoded strings

Methods

getThingThatIsEncoded

Find a key inside a string that may or may not be encoded.

Encoded::getThingThatIsEncoded($strange, $thing)

Example

Find a key in a JSON encoded array:

  use \Pbc\Bandolier\Type\Encoded
  $string = "{"foo":"bar"}"
  Encoded::getThingThatIsEncoded($string, 'foo')
  // returns "bar"

Find a key in a serialized array:

  use \Pbc\Bandolier\Type\Encoded
  $string = "a:1:{s:3:"foo";s:3:"bar";}"
  Encoded::getThingThatIsEncoded($string, 'foo')
  // returns "bar"

getEncodeType

Check for the encoded type of a string.

Encoded::getEncodeType($string)

Example

Check to see if string is a JSON array:

  use \Pbc\Bandolier\Type\Encoded

  $string = "{"foo":"bar"}"
  Encoded::getEncodeType($string);
  // returns "json"

Check to see if string is a serialized array:

  use \Pbc\Bandolier\Type\Encoded

  $string = "a:1:{s:3:"foo";s:3:"bar";}"
  Encoded::getEncodeType($string)
  // returns "serialized"

isJson

Check to see if a string is a JSON array.

Encoded::isJson($string)

Example

Check to see if string is a JSON array:

  use \Pbc\Bandolier\Type\Encoded

  $string = "{"foo":"bar"}"
  Encoded::isJson($string);
  // returns true

Check to see if string is a JSON array will return false if not:

  use \Pbc\Bandolier\Type\Encoded

  $string = "a:1:{s:3:"foo";s:3:"bar";}"
  Encoded::isJson($string);
  // returns false

unpackJson

Decode a JSON array from string.

Encoded::unpackJson($string, $associativeArray = true)

Example

Decode a JSON array:

  use \Pbc\Bandolier\Type\Encoded

  $string = "{"foo":"bar"}"
  Encoded::unpackJson($string);
  // returns ["foo" => "bar"]

isSerialized

Checks string is a serialized object.

Encoded::isSerialized($string)

Example

Check to see if string is a serialized object:

  use \Pbc\Bandolier\Type\Encoded

  $string = "a:1:{s:3:"foo";s:3:"bar";}"
  Encoded::isSerialized($string);
  // returns true

Check to see if string is a a serialized object will return false if not:

  use \Pbc\Bandolier\Type\Encoded

  $string = "{"foo":"bar"}"
  Encoded::isSerialized($string);
  // returns false

unpackSerialized

Decodes a JSON array from string

Encoded::unpackSerialized($string)

Example

Decode a serialized object:

  use \Pbc\Bandolier\Type\Encoded

  $string = "a:1:{s:3:"foo";s:3:"bar";}"
  Encoded::unpackSerialized($string);
  // returns ["foo" => "bar"]

isBase64

Check to see if a string is a base64 encoded string or not. This is experimental!

  use \Pbc\Bandolier\Type\Encoded

  $string = base64_encode("a:1:{s:3:"foo";s:3:"bar";}")
  Encoded::isBase64($string);
  // returns true

unpackBase64

Unpack a base64 encoded string. This is experimental!

  use \Pbc\Bandolier\Type\Encoded

  $string = base64_encode("hello world")
  Encoded::unpackBase64($string);
  // returns "hello world"