문제

도움이 필요해요 이 향상된 기능들에 대한 분석에서 링크 트위터입니다.을 만들에 대한 링크 검색@빠르고,무료이며,재미.그것은 모든 잘 작동하는 문제입니다 경우 해시태그나@답변은 문장 끝에 문자를 공백없이,그것에 추가되/A URL.

예를 들면 나도 트윗이"내가 정말 좋아#피자,#pop",대한 링크를#피자가 잘못되는 것이기 때문에 쉼표가 있습니다.

나는 아주 좋지 않으로 정규식,이것이 나를 잠시 그냥 이 작업,그래서 어떤 도움이 될 것이 굉장하다!

function parse_tweet($description, $colour='', $external=false) {
if ($external == true) $pre = 'http://politwitter.ca'; else $pre = '';
$description = preg_replace("/(http:\/\/[^\s]+)/", "<a href=\"$1\" target=\"_blank\">$1</a>", $description);
$description = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise", "'\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>'", $description);
$description = preg_replace("#(^|[\n ])@([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"".$pre."/user/\\2\" rel=\"nofollow\">@\\2</a>'", $description);
$description = preg_replace("#(^|[\n ])\#([^ \"\t\n\r<]*)#ise", "'\\1<a href=\"".$pre."/hash/\\2\" rel=\"nofollow\" class=\"hash ".$colour."\">#\\2</a>'", $description);
return $description;

}

도움이 되었습니까?

해결책

가장 간단한 수정의의 코드를 무엇을 원하는:

$description = preg_replace("#(^|[\n ])\#(\w+)#ise", "'\\1<a href=\"".$pre."/hash/\\2\" rel=\"nofollow\" class=\"hash ".$colour."\">#\\2</a>'", $description);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top