Solved

php with preg match

Posted on 2011-09-08
3
307 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 500 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

828 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