i have a url: /events/details/16-righteous-turkeys.html
that i need to change to /turkeys
i have no idea how to go about doing this...and would really appreciate the help.
i have a url: /events/details/16-righteous-turkeys.html
that i need to change to /turkeys
i have no idea how to go about doing this...and would really appreciate the help.
The first thing you need to do is specify your problem more clearly.
What you've posted can be achieved simply by assigning the value "/turkeys" to your variable (maybe you want to use an 'if' statement to check it previously contains "/events/details/16-righteous-turkeys.html").
So you need to specify (in English first) how you figured out what the new value should be. An example that may fit what you've posted:
"I need to take my original path and, ignoring the directories, look at the filename on the end. From that, I need to extract everything between the last hyphen and the .html extension on the end. I then need to replace the entire thing with what I've extracted ("turkeys" in this case)".
If you need to always extract the last word between the hyphen and .html
the following should do it:
$string = '/events/details/16-righteous-turkeys.html';
$pattern = '/^.*\-(\w+)\.html$/i';
$replacement = '/${1}';
echo preg_replace($pattern, $replacement, $string);