HTML dom에서 substr()
을 어떻게 사용할 수 있습니까? 나는 모든 html 태그를 유지하고 단지 텍스트를 짧게하고 싶다.html dom의 PHP substr
$str = '<div><a href="http://www.weather.com">Today is a nice day</a></div>';
$part1 = preg_replace("/<a(.*?)>(.*?)<\/a>/i",substr('\\2', 0,10),$str).'...';
$part2 = preg_replace("/<a(.*?)>(.*?)<\/a>/i",'\\2',$str);
echo str_replace($part2,$part1,$str);// nothing change
// I need <div><a href="http://www.weather.com">Today is a...</a></div>
가능한 중복 http://stackoverflow.com/questions/을 7159695/html-errors-when-truncating) – Yoshi
@ Yoshi : 중복이 아님 – rabudde
@rabudde 어떻게 중복되지 않습니까? html 구조를 손상시키지 않고 텍스트 노드를 잘라내는 방법을 다루고 있습니까? – Yoshi