2016-09-26 6 views
0

문자열을 max 35 character으로 중단하고 싶지만 지능적으로 중단하고 싶습니다. 내가 아래 문자열이 있다고 가정하자 :PHP 문자열의 더 똑똑한 문자열 중단

street name, sector name, city, state, pincode 

또는

ABC Heights, Golf Road, City Test, City Sector 

지금, 나는 이러한 문자열 어쨌든 침입 할 할을하지만, 어떤 잘못 라인을 중단하지 지적한다.

예 : 휴식은 여기

SMart Wrap

하지만 행운

ABC Heights, Golf Road,<br/> 
City Test, City Sector 

ABC Heights, Golf Road,City Te<br/> 
st, City Sector 

내가 시도하지 해답이 될 수 있습니다.

+0

[wordwrap] (http://php.net/manual/en/function.wordwrap.php) + [nl2br] (http://php.net/nl2br) –

답변

1

ABC Heights, Golf Road, City Test, 
City Sector 

초래

<?php 
    $string = "ABC Heights, Golf Road, City Test, City Sector"; 
    echo wordwrap($string, 35, "<br />\n"); 
?> 

은 자세한 내용은 http://php.net/manual/en/function.wordwrap.php를 참조하십시오.

+0

이 깨진 문자열을 2 개의 diff로 저장할 수 있습니까? 변수 – Gags

+0

그래, 단락 기호에서'explode' 만하면됩니다 -이 경우'$ lines = explode ("
\ n", $ wordwrap_string);'그런 다음 $ lines [0]/[1]을 원하는 위치에 설정하십시오. – Carl