Jump to content

preg_match help


devWhiz

Recommended Posts

I fail miserably at regex

 

I need to get the string in between app# and &open

 

so it would be

 

$matches = "bz8D1qQq0rQHQ2WEQ5fGG3KIWNIFUqIhwwSRVlob%2b7bR7RH%3d";

 

 


app#bz8D1qQq0rQHQ2WEQ5fGG3KIWNIFUqIhwwSRVlob%2b7bR7RH%3d&open


 

and if someone could post a link to where I might be able to grasp the preg_match function, aside from the manual that would be great.. Thanks

Link to comment
Share on other sites

and if someone could post a link to where I might be able to grasp the preg_match function, aside from the manual that would be great.. Thanks

To learn how to use this function you'll want to learn regular expressions. regular-expressions.info is good learning resource and http://gskinner.com/RegExr/ is a good site for testing out your regex patterns.

 

A regex pattern that you can use would be

preg_match('~app#(.*)&open~', $string, $matches);

 

preg_match will return an array of matches

Array
(
    [0] => app#bz8D1qQq0rQHQ2WEQ5fGG3KIWNIFUqIhwwSRVlob%2b7bR7RH%3d&open
    [1] => bz8D1qQq0rQHQ2WEQ5fGG3KIWNIFUqIhwwSRVlob%2b7bR7RH%3d
)

use $matches[1] to get the match string between the # and &. If you need to match multiple instances of app#{WHATEVER}&open then you'll need to use preg_match_all

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.