Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

can someone tell me what is this? about regular expression

Posted on 2008-10-13
5
Medium Priority
?
187 Views
Last Modified: 2012-05-05
http://fdsawfa.com/iafdqe.html?&page=286

and i want to use the preg match all or any other function
to output for me
286

soo people told me to use
preg_match_all('/(?<=[?&]page=)[^&?]*/',$yourvar,$match)){


can someone tell me exactly what eatch part is?
beacuse i want to know what i am using and not only to use it
0
Comment
Question by:mgtm3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 8

Assisted Solution

by:nahime
nahime earned 1400 total points
ID: 22706343
If you need 286 instead of use regex you can read that value in the GET array:

echo $_GET['page'];

This will output 286
0
 
LVL 8

Accepted Solution

by:
nahime earned 1400 total points
ID: 22706380
This applies only if you are trying to get that value from the URL of the script otherwise you have to use that preg_match.
An example is:
<?php
$yourvar = "http://fdsawfa.com/iafdqe.html?&pippo=4&page=286";
preg_match_all('/(?<=[?&]page=)[^&?]*/',$yourvar,$match);
echo $match[0][0];
?>

Open in new window

0
 
LVL 8

Assisted Solution

by:nahime
nahime earned 1400 total points
ID: 22706542
The part are:
$yourvar -> The variable containing the querystring
$match -> The variable in which the result of the regex is stored
The regular expression remove from $yourvar everything before the first ?
Remove everything between the first ? and "page="
Remove page=
Remove from the first & after "page=" until the end of string (in the example is not needed but is usefull if the string is something like http://fdsawfa.com/iafdqe.html?&pippo=4&page=286&ghgh=ghgh)

So what remain is only the number of page.
The function return 1 if matched the regex or 0 if not and in the array you have what remain of the string exploded into an array.
0
 
LVL 27

Assisted Solution

by:ddrudik
ddrudik earned 600 total points
ID: 22708420
mgtm3, here's an explanation:
----------------------------------------------------------------------
  (?<=                     look behind to see if there is:
----------------------------------------------------------------------
    [?&]                     any character of: '?', '&'
----------------------------------------------------------------------
    page=                    'page='
----------------------------------------------------------------------
  )                        end of look-behind
----------------------------------------------------------------------
  [^&?]*                   any character except: '&', '?' (0 or more
                           times (matching the most amount possible))
----------------------------------------------------------------------
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 22772246
Thanks for the question and the points.
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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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 …
Suggested Courses

604 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