dozvha2490
2016-11-25 03:08
浏览 43

包装字符串PHP

I have a problem with my code, i have this code that create image from external source of image & string. I used json to get the string.

My problem is if i used the string from json data i could not get the proper wrapping of string like this:

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;

But if i declare and set string directly i got the output that i want like this:

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.";

I dont think the error or the problem is on the code for wrapping the text on my image. I think it is on the json data. How can i fix this?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dragon4808 2016-11-25 04:09
    已采纳

    The text has symblols. Just replace them:

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

    or without a regular expression:

    $string = str_replace("
    ", ' ', $data->text);
    
    点赞 评论

相关推荐 更多相似问题