Solved

can someone tell me what is this? about regular expression

Posted on 2008-10-13
5
178 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
  • 3
  • 2
5 Comments
 
LVL 8

Assisted Solution

by:nahime
nahime earned 350 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 350 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 350 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 150 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now