How can i call in php words from url?
Example 1
http://myurl.com/keyword-one
I want to display "Keyword One" as page title in php
Example 2
http://myurl.com/keyword/keyword-two
I want to display "Keyword Two" as page title in php
Thank you! :-)
the simplest solution in those cases would be using (untested code, but should work):
<?php
//get path
$urlPath = $_SERVER["REQUEST_URI"];
//get last element
$end = array_slice(explode('/', rtrim($urlPath, '/')), -1)[0];
//replace dashes with spaces and display
echo ucwords(str_replace('-',' ',$end));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.