2014-02-17 2 views
-1

우리는 동적 게시물이 우리가 URL을변환 배열 (분할 3 자)

$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); 
     } 

에 사용하기 위해 문자열의 3 개 단어를 분할해야하며,이 URL 매개 변수

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

내 URL입니다 위로 :

sitename.com/123/THIS.html
하지만
sitename.com/123/THIS되어야 SAMPLE.ht IS ml의

+0

을 당신은'$ this-> post_message'의 처음 세 단어를 얻으려면? 그냥 명확히 .. – Vainglory07

+0

예, 나는 $ this-> post_message의 3 단어를 전나무 싶어. – user3261715

답변

1

는이

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

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

var_dump($string); 

//result ... 

string(14) "THIS IS SAMPLE" 
0

아마 정규 표현식 마법사가 이것보다 더 잘 할 수있는 시도하지만 :

$this->post_message = "THIS IS SAMPLE STRING FOR TEST"; 
$result = preg_match("/^([^ ]+(?: [^ ]+)?(?: [^ ]+)?)/", $this->post_message, $matches); 
if ($result) { 
    $bodypost = $matches[1]; 
}