Page 1 of 1

regex for this simple string please

Posted: Wed Mar 16, 2005 2:43 am
by mjseaden
Hi there,

I have a script called sitemap_ (that's right, sitemap with _ on the end and no extension).

I am detecting any parameter (REQUEST_URI) after the sitemap_ either in the form

sitemap_X
sitemap_X_Y

can anyone tell me what regex I use to determine whether it is of either type, and if so, what X and Y are in the string?

Many thanks

Mark

Posted: Wed Mar 16, 2005 3:59 am
by thomas777neo
You don't necassarily need to use regex.

You could probably use one of these functions:

split
explode
substr
strlen

Or a comination thereof to get X or Y, if I understand the question correctly.

e.g.

Code: Select all

<?php
$url = "blah_x_y";

$breakup = explode("_",$url); // turns $breakup into an array ("blah","x","y")

$default = $breakup[0]; // blah
$x = $breakup[1]; // x
$y = $breakup[2]; // y
?>
Just a simple non generic example of how you can manipulate strings.


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Wed Mar 16, 2005 4:48 am
by Chris Corbyn
Yes I agree. I'm all for RegExp's but in this instance, I'd go with explode().

That way it's clearer to see what you have extracted by just looping over your obtained array with foreach(), since there could be any number of arguments in the string. :wink: