Solved

can someone tell me what is this? about regular expression

Posted on 2008-10-13
5
179 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can define this $_GET["page"]  variable on my page? 5 32
php email 2 26
php call to a non-object 3 32
Checking if varaible is empty 6 29
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 count occurrences of each item in an array.

910 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

21 Experts available now in Live!

Get 1:1 Help Now