Solved

php with preg match

Posted on 2011-09-08
3
304 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

776 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