I'm definately not a regexp wiz.... need some suggestions here:
grab PHP_SELF, strip the end filename off and the 2 directories
preceeding it...
This is what I've come up with so far, except I'd like to replace the
..html for any extension and I've tried it but doesn't work... and I've
also tried parsing backing a second directory but no luck, maybe you
have an alternative solution:
--- snip ---
What I have tried:
// retrieves URL of itself, then strips the directories only leaving
the filename
$PHP_SELF = $_SERVER['PHP_SELF'];
$new = preg_replace("/[^\/](.*?)[$\/]/mis",'',$PHP_SELF);
$new = preg_replace("/\//mis",'',$new);
// replace the file only so we have the directory and append the
contact form onto it
$expression =
sprintf("/[$\/](?=...)([a-z0-9]+.\.[a-z]+)/mi",$new); // or
$expression = sprintf("/[$\/](?=...)([a-z0-9]+.\.htm?)/mi",$new); or
$expression =
sprintf("/[$\/](?=...)([a-z0-9]+.\.htm?)(?<=...)(-[a-z][\/])/mi",$new);
$contactform = preg_replace($expression,'',$PHP_SELF);
$contactform = $contactform.'/contact_form1.html';
What I have now:
// retrieves URL of itself, then strips the directories only leaving
the filename
$PHP_SELF = $_SERVER['PHP_SELF'];
$new = preg_replace("/[^\/](.*?)[$\/]/mis",'',$PHP_SELF);
$new = preg_replace("/\//mis",'',$new);
// replace the file only so we have the directory and append the
contact form onto it
$expression = sprintf("/[$\/](?=...)%s/mi",$new);
$contactform = preg_replace($expression,'',$PHP_SELF);
$contactform = $contactform.'/contact_form1.html';
--- snip ---
PHP_SELF = /dirname1/dirname2/dirname3/dirname4/somefile.html
which generally results in
/dirname1/dirname2/dirname3/contact_form1.html
but what I would like is to also remove dirname3 as well resulting in:
/dirname1/dirname2/contact_form1.html