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. Link to comment https://forums.phpfreaks.com/topic/79710-sos-reg_replace-syntax-question/ 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); Link to comment https://forums.phpfreaks.com/topic/79710-sos-reg_replace-syntax-question/#findComment-403711 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 Link to comment https://forums.phpfreaks.com/topic/79710-sos-reg_replace-syntax-question/#findComment-403891 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); Link to comment https://forums.phpfreaks.com/topic/79710-sos-reg_replace-syntax-question/#findComment-403981 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.