Question

we have dynamic posts and we should split 3 words of string for use in url

$this->post_message = "THIS IS SAMPLE STRING FOR TEST";
if (strlen($this->post_message) > 5) {
        $key='<> ";,/\][{}|`~!#$%^&*_+=-';
        $bodypost1 =trim($this->post_message,$key);
        $bodypost2 = explode (' ',$bodypost1,3);
        $bodypost = array_shift(',',$bodypost2);
        }else{

        $bodypost2 = explode (' ',$this->post_message,3);
        $bodypost = array_shift(',',$bodypost2);
        }

and this is URL parameters

$this->permalink        = $C->SITE_URL.'view/'.($type=='private'?'priv':'post').':'.$this->post_id.'/'.$bodypost.'.html';

and my url back to :

sitename.com/123/THIS.html
but should be
sitename.com/123/THIS IS SAMPLE.html

Était-ce utile?

La solution

Try this

$message = "THIS IS SAMPLE STRING FOR TEST";

$string = implode(' ', array_slice(explode(' ', $message), 0, 3)); 

var_dump($string);

//result ...

string(14) "THIS IS SAMPLE"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top