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
https://forums.phpfreaks.com/topic/239056-preg_match-help/
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
https://forums.phpfreaks.com/topic/239056-preg_match-help/#findComment-1228291
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.