sageman Posted December 1, 2007 Share Posted December 1, 2007 I want to use the URI as the page title. it currently reads as: word-word-word.html I want it to read as: word word word How can I modify the code in red to achieve these results for the page title? $filename = $_SERVER['REQUEST_URI']; $filename1 = split( '[/]', $filename ); $last = end($filename1); $last = ereg_replace("\.$", "", $last); $underscore_key = $last; $index_key = eregi_replace("(\.)([a-z]{2,4})$", '', $last); $index_key = ereg_replace("\-", " ", $last); $index_key = ereg_replace(".html", "", $last); Thanks. Quote Link to comment Share on other sites More sharing options...
c4onastick Posted December 1, 2007 Share Posted December 1, 2007 I'd use the preg suite. In general, it's much better than ereg. I would modify the whole section of code work something like this: $filename = 'word1-word75-elephant.html'; $filename = preg_replace('/\..+$/', '', $filename); //chop off the extension $filenames = preg_split('/-/', $filename); //split the words into an array $filename = join(' ', $filenames); //rejoin the array with spaces print_r($filename); Or I suppose you could cut out the middle-man and use: $filename = 'word1-word75-elephant.html'; $filename = preg_replace('/\..+$/', '', $filename); $filename = preg_replace('/-/', ' ', $filename); print_r($filename); Quote Link to comment Share on other sites More sharing options...
sageman Posted December 1, 2007 Author Share Posted December 1, 2007 Thanks for your help so far...almost there. I replaced $filename with $index_key because of my template. The code below works great except that it returns /word word word instead of word word word How can I remove the / at the beginning $index_key = $_SERVER['REQUEST_URI']; $index_key = preg_replace('/\..+$/', '', $index_key); $index_key = preg_replace('/-/', ' ', $index_key); Thanks Quote Link to comment Share on other sites More sharing options...
sageman Posted December 2, 2007 Author Share Posted December 2, 2007 Solved...i think. thanks a lot for all your help $index_key = $_SERVER['REQUEST_URI']; $index_key = preg_replace('/\..+$/', '', $index_key); $index_key = preg_replace('/-/', ' ', $index_key); $index_key = preg_replace('/\//', '', $index_key); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.