Reputation: 399
I have written the code in javascript but i need it to happen in serverside, The function gets the part of the requested url and if it's match my switch it's change the ducoment title.
Here is the Javascript:
$(document).ready(function(e){
e=window.location.href;
if(e.match(/\\?case=(.*)/)){
x=e.match(/\\?case=(.*)/);
y=x[1];
switch(y){
case :"t"
document.title ="Title2";
break;
case :"s"
document.title ="Title3";
break;
default:
/* code ... */
break;
}
}
});
In this code if my url is "http://url.com/?case=t" the title of document going to change to "Title2".
How can i write it in php? the problem is getting the url match!
Upvotes: 0
Views: 147
Reputation: 1323
You mean getting the variable case? Because that's what you used in JavaScript
And if so, an example in PHP would be having this in the header
<?php
$case = $_GET['case'];
switch ($case) {
case 't':
$title = 'Title 2';
break;
}
echo "<title>". $title . "</title";
?>
Upvotes: 4