2012-10-20 4 views
0

문자열을 회전시키기 위해 스핀 기능을 만들고 싶지만이를 수행 할 때 문제가 발생했습니다. 이임의의 문자열 회전기 문제

$spin_words=array('Word1','Word2','Word3'); 
$text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."; 

그래서 내가

을 임의의 단어를 추가 할 같은 문자열에서 ranom 스핀 | {안녕하세요 안녕하세요}하지만 내가 원하는 것은 차이가 나는 allready 변화와 같은 문자열에 단어를 스핑하는 방법을 알고

Lorem Ipsum은 단순히 [Word1] 인쇄의 더미 텍스트 및 조판 업계입니다.

또는

로렘 입숨는 인쇄 [Word2] 및 조판 업계 단순히 더미 텍스트이다.

또는

로렘 입숨 단순히 더미 프린팅 텍스트 조판 업계 [Word3]이다.

그래서 어떤 도움들

관련

답변

0

당신은

$words = array('Word1','Word2','Word3'); 
$text = "Lorem Ipsum is simply dummy text of the printing and typesetting industry."; 
echo wordInString($text,$words); 
echo wordInString($text,$words); 

출력 예

Lorem Ipsum is simply dummy Word1 text of the printing and typesetting industry. 
Lorem Ipsum is simply dummy text of the printing Word2 and typesetting industry. 

사용 기능

시도 할 수 있습니다
function wordInString($text,array $words) { 
    $textNew = array(); 
    $p = mt_rand(0, substr_count($text, " ")); 
    $tok = strtok($text, " \n\t"); 
    $x = 1; 
    while ($tok !== false) { 
     $textNew[] = $tok and $x == $p and $textNew[] = $words[array_rand($words, 1)]; 
     $tok = strtok(" "); 
     $x ++; 
    } 
    return implode(" ", $textNew); 
} 
+0

감사합니다. –