Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php with preg match

Posted on 2011-09-08
3
Medium Priority
?
315 Views
Last Modified: 2012-06-27
how can I match this site when the last digits always change
site.com/?d=YS98IIR06

Open in new window

0
Comment
Question by:XK8ER
  • 2
3 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 36506105
you mean the last "06" only?
$var='site.com/?d=YS98IIR06';

If yes and you want to limit to two digits only
preg_match('#site.com/[?]=YS98IIR\d\d#', $var)

If you want to limit to at least one digit:
preg_match('#site.com/[?]=YS98IIR\d+#', $var)


zero or more digits:
preg_match('#site.com/[?]=YS98IIR\d*#', $var)
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 2000 total points
ID: 36506414
Or if the entire value of the variable can change:
preg_match('#site.com/\?d=[^&]+#', $var);
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36506420
Note that we can provide all sorts of different patterns that will match - what's also important though is what you want to NOT match. You might like to describe that too.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question