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
Solved

can someone tell me what is this? about regular expression

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

860 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