Forum Moderators: coopster
Example:
$String = "qx1234";
preg_match("/([a-zA-Z]+)([0-9]+)/",$String,$Match);
print_r($Match);
Output:
Array
(
[0] => qx1234
[1] => qx
[2] => 1234
)
[0] is the whole matching string, and the subsequent array values are the captured parts of the string.
Of course you will have to modify the regex to suit your needs, but this particular example will work for the string you supplied.
Hope this helps!
The substr() seems to fit my needs best. I've used it in a file called ref.php as follows (note that there are ten lines in this file) ...
<?php
if (substr($CurrentPage, 0, 2) === "qx") {
$refnum = substr($CurrentPage, -4);
switch ($refnum):
case 00001: header("Location: [msn.com");...]
case 00002: header("Location: [google.com");...]
default: header("Location: [example.com...] ;
endswitch;
}
?>
I include this file in the code before the <HTML> tag in my file called "content.php" as in the following extract ...
$URL_data = explode("/", getenv("REQUEST_URI"));
$_SESSION['CurrentPage'] = $URL_data[2] ;
// Redirect test of ref.php shown above
include '/var/www/html/php/ref.php';
// Include page sought if available
if(file_exists('/var/www/html/php/' . $CurrentPage . '.php'))
{include '/var/www/html/php/' . $CurrentPage . '.php' ;}
else
{include '/var/www/html/php/main.php'; $CurrentPage='main';}
?>
<html>
I am getting a parser error that says there is an unexpecte "$" in line 11 of ref.php. Then the HTML loads as I would expect since the URL_data[]2] did not include the "qx." Since I only have 10 lines in ref.php, I am confused.
Cam amyone explain or help?
Many thanks.
[edited by: jatar_k at 8:58 pm (utc) on Jan. 27, 2005]
I added a semicolon after the last curly bracket at the end of an "if" statement and the parser error did not return an error.
if ($LandingPage == "") { $_SESSION['LandingPage'] = $URL_data[2] ; } ; <-- the semicolon I added
Only problem is, now my logic doesn't work and I don't get content included. Oh me, oh my.
Many thanks for the guidance.