Hi, please help. $abc = get_settings('home') . strip_tags($item->get_title()); echo $abc; Code (markup): The first line generates link from title, how do I display only 5 first words in the URL? ex: hxxp://www.domain.com/let-me-show-you-that-i-have-very-very-very-very-long-urls result: hxxp://www.domain.com/let-me-show-you-that Thanks for help
There's bound to be a better way but I'd do something like this $abc = get_settings('home') . strip_tags($item->get_title()); $bits = explode('/',$abc); $full = $bits[count($bits)-1]; $words = explode('-',$full); $num = min(count($words), 4); $short = ''; for ($i = 0; $i <= $num, $i++) { $short .= $words[$i]; } $bits[count($bits)-1] = $short; $newlink = implode('/', $bits); PHP: I haven't tested that so it may have some errors but read through it, do some var_dumps where you aren't sure what is going on, check php.net and it should work.
If you want to reduce the length of the url, then my guess would be, you should reduce it according to its length and not by no. of words. for e.g. try something like: $abc = substr($abc, 0, 70); PHP: Which will limit the url to 70 characters.
That's it. Good answer. Wahyuagung, It looks like you're using a framework, if this is the case stop and learn PHP first. You shouldn't touch a framework if you don't know the underlying language..