I have a php function that works for what i need but now i've found that there is chance for it to fail. I use mod rewrite to rewrite urls and this function needs urls to be rewritten for it to work. If i have 2 pages that have been rewritten as the same even though they are not the same, it could fail.
The function reads the url and splits it into parts using the / as the separator.
What i want to be able to do is check if the url has the word 'forum' in it and if it does query the database using the following url parts in the query.
Say i have a url like http://www.mydomain.com/forum/1/2/6 i would like to get the 1 and 2 for my query which would be the boardid and topicid. The last bit would be the page number.
This is a rewritten url which would normally look like http://www.mydomain.com/topic.php?boardid=1&topicid=2&pagenum=6 but using the function I wouldn't be able to split becuase there are no /.
The query i can do easy enough, it's just checking the url to make sure that 'forum' is in there then do the query. If it's not in the url then carry on as normal.
here is the code for my php breadcrumb
function breadcrumb(
$home = 'Home', // Name of root link
$division = ' / ', // Divider between links
$hidextra = true, // Toggle hide/show get data and fragment in text
$index = false, // Toggle show/hide link to directory if it does not contain a file
$indexname = 'index.php' // The definition of the file the directory must contain
) {
$breadcrumb="";
// Requested addons...
$extension = '.php'; // Extension to cut off the end of the TEXT links
$ifIndex = 'index.php'; // Filename of index/default/home files to not display
// End requested addons
$whole = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if(stristr($whole,"contact-bidder")) {
$whole = substr($whole,0,strrpos($whole,'/'));
}
$parts = explode('/', $whole);
$parts[0] = 'http://'.$parts[0];
$array = array('-', '%20');
$breadcrumb .= "<a href=\"{$parts[0]}\">{$home}</a>{$division}";
$k = 1;
for ($i=1;$i < sizeof($parts);$i++) {
$uri = '/';
while ($k <= $i) {
$uri .= $parts[$k];
if ($k != (sizeof($parts)-1)) $uri .= '/';
$k++;
}
if (($index && is_dir($_SERVER['DOCUMENT_ROOT'].$uri) && is_file($_SERVER['DOCUMENT_ROOT'].$uri.$indexname)
|| !$index
|| !is_dir($_SERVER['DOCUMENT_ROOT'].$uri)) && $parts[$i] != $ifIndex) {
$breadcrumb .= "<a href=\"$uri\">";
if ($hidextra) {
$breadcrumb .= rtrim(preg_replace("/\?.*$/", '', ucwords(str_replace($array," ",$parts[$i]))), $extension);
}
else {
$breadcrumb .= rtrim(ucwords($parts[$i]), $extension);
}
$breadcrumb .= '</a>';
}
else {
$breadcrumb .= ucwords(str_replace($array," ",$parts[$i]));
}
if (isset($parts[($i+1)])) {
$breadcrumb .= $division;
}
$k = 1;
}
return $breadcrumb;
}
If that isn't possible or easy, is there a way i can split on the ? and & and get only what is before the ? and after = for each variable in the url