Jump to content
Sign in to follow this  
Prodjex

PHP parse_str

Recommended Posts

Quick example of how to use PHP’s parse_str command.

Here is an example of my data:

$source = "access_token=CAAWhyYsjaWsBAOCwjZCs&expires=5180531";

What I’m trying to do is just grab the string of the access_token variable from the URL.  So above I’ve dropped it into the $source PHP variable.

Now using parse_str I can get that into an array like so:

$source = "access_token=CAAWhyYsjaWsBAOCwjZCs&expires=5180531";
parse_str($source, $output);

Next I just need to select the section I want, for this example I need the access_token, so my final code is:

<?php
            $source = "access_token=CAAWhyYsjaWsBAOCwjZCs&expires=5180531";
            parse_str($source, $output);
            echo $output['access_token'];?>

If I wanted the expires field I’d modify to this:

<?php
            $source = "access_token=CAAWhyYsjaWsBAOCwjZCs&expires=5180531";
            parse_str($source, $output);
            echo $output['expires'];?>

Output demo

The post PHP parse_str appeared first on Kansas City Web Consulting | Kansas City Web Development.

View the full article

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...