2017-11-06 6 views
-2

텍스트 링크를 추가하려면 html preg_match가 필요합니다.preg_match 텍스트의 링크

'![a-z][a-z-]+://!i' 

예 : 현재 사용

some text mylink.com 
Become 
some text <a href="mylink.com">mylink.com</a> 

을 그리고 그 괜찮습니다. 그러나 나는 이미 첫 번째 코드에서 'a href'를 가지고 있으므로 건너 뛸 필요가 있습니다. 첫 번째 빈 공간이있는 링크를 감지하려면이 preg_match를 변경해야합니다. 어쩌면 :

'!^[a-z][a-z-]+://!i' 

그러나이 작업은 도움이되지 않습니까?

+0

https://stackoverflow.com/questions/13105960 사용/replace-text-link-as-link-with-preg-replace 당신의 regex는 너무 명확해서 의도 한 URL을 정확하게 찾을 수 없습니다. –

답변

0
'/<a\s+(?:[^"'>]+|"[^"]*"|'[^']*')*href=("[^"]+"|'[^']+'|[^<>\s]+)/i' 

는하거나 simpledom praser =>http://simplehtmldom.sourceforge.net/ 예를 들어, SO 여기 링크를 교체하는 방법에도에 구멍 많은데 질문이있다

//from string 
$html = str_get_html($links); 

//or from webpage 
$html = file_get_html('www.example.com'); 

foreach($html->find('a') as $link) { 
    echo $link->href . '<br />'; 
}