2016-11-25 1 views
0

내 코드에 문제가 있습니다. 외부 소스 & 문자열에서 이미지를 만드는 코드가 있습니다. 나는 json을 사용하여 문자열을 가져 왔습니다.줄 바꿈 PHP

내 문제는 내가 JSON 데이터의 문자열을 사용하는 경우이 같은 문자열의 적절한 포장 얻을 수있다 :

http://prntscr.com/dbhg4n

  $url = 'https://bible-api.com/Psalm100:4-5?translation=kjv'; 

      $JSON = file_get_contents($url); 
      $data = json_decode($JSON); 
      $string = $data->text; 

을하지만 난 선언하고 직접 문자열을 설정하면 내가 가진 내가 이런 식으로 원하는 출력 :

http://prntscr.com/dbhg7q

$string = "Enter into his gates with thanksgiving, and into his courts with praise: be thankful unto him, and bless his name. For the Lord is good; his mercy is everlasting; and his truth endureth to all generations."; 

오류 또는 문제가 내 이미지의 텍스트를 줄 바꿈하는 코드에 있다고 생각하지 않습니다. 나는 그것이 json 데이터에 있다고 생각한다. 이 문제를 어떻게 해결할 수 있습니까?

+0

것을 수행 위해서 var_dump ($ 데이터); 주기? – flauntster

+0

보기 소스 : https : //bible-api.com/Psalm100 : 4-5? translation = kjv 추가 된 줄 바꿈 참조 –

답변

0

text에는 \n 개의 symblols가 있습니다. 그냥 교체 :

$string = preg_replace("/\n/", ' ', $data->text); 

또는 정규 표현식없이

:

$string = str_replace("\n", ' ', $data->text);