2012-02-05 3 views
-1

데이터베이스에 많은 트윗이 있으므로 "RT @username : ... 나머지 트윗"의 RT를 [RT]로 바꾸고 싶지만 " RT "는 짹짹의 시작 부분에있다. 입력 예를 들어 것언제든지 문자열이 "RT"로 시작될 때마다

RT @username I'm having one jolly good time!! 
RT @username RT @username this is fun 
I am not using RT as a label - I use my own "retweet" label :P 
rt @name here rt is lowercase 

출력 :

[RT] @username I'm having one jolly good time!! 
[RT] @username RT @username this is fun 
I am not using RT as a label - I use my own "retweet" label :P (no changes) 
[RT] @name here rt is lowercase 

이 정규식 또는 일반 PHP를위한 작업인가

그래서 (함수는 대소 문자를 구분하지 않아야합니다)? 어떤 조언을 부탁드립니다!

답변

2

나는 정규식이 할 것 : 당신의 입력 문자열이 여러 줄 수없는 경우

$result = preg_replace("/^RT/uim", "[RT]", $searchText); 

, 당신은 m을 제거 할 수 있습니다.

0

PHP가 필요하지 않습니다. 한 단계에서 직접 mySQL에서 수행하십시오.

UPDATE 
    tweet_table 
SET 
    tweet_text = '[RT] ' + SUBSTRING(tweet_text, 4) 
WHERE 
    SUBSTRING(tweet_text, 1, 3) = 'RT ' 
관련 문제