ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi,
In this php code the file_get_contents(), gets the text and passing to write on image the problem is, file_get_contents() passing all the text in one line not breaks to each new line, so all the text in image is in one line, how i can break to each new line:
It looks like that's what file_get_contents does..."Reads entire file into a string"
Try file, which will load each line into an array element, then loop the array to populate $text, appending a line feed at the end of each element.
Or fget, to retrieve one line at a time and add to $text, again with appended line feed.
Alternate (kinda geeky) idea: Put some "special character" (something like xxx) at the end of each line, then substitute \n for xxx in $text before doing the draw function.
It looks like that's what file_get_contents does..."Reads entire file into a string"
Try file, which will load each line into an array element, then loop the array to populate $text, appending a line feed at the end of each element.
Or fget, to retrieve one line at a time and add to $text, again with appended line feed.
I'm guessing that you are outputting to a web page. In this case, "line feed" would not be relevant: you would use the <br/> tag.
One simple way to do it is to split() the string into an array, then immediately join() that array using '<br/>' as the separator. This will reassemble the string with a break separating each piece. Output the resulting string followed by another break. That's a convenient way to do it if memory is not an issue.
If it might be, you can read the file "line by line" and output each line followed by a break. An arbitrarily-large file can be output in this way.
Last edited by sundialsvcs; 08-01-2017 at 08:41 AM.
I'm guessing that you are outputting to a web page. In this case, "line feed" would not be relevant: you would use the <br/> tag.
Perhaps...although the posted script is using the data in $text to create an image (.png) file. In any case, that's why I used "line feed" instead of \n or CRLF or <br>, because I didn't know what was specifically appropriate.
Again, using php's file function will load an array as you suggest, and yes, using php's join() function could be used to add the "line feed"
If you are generating an image and outputting that image, then there are PHP functions to do that, and it is imperative that your program produces no other output. (For instance, a single blank space following a ?> tag at the end of the file, which will corrupt the image output by adding a space-valued byte at the end.)
Thanks for reply, i run the code it print the whole text in one line, can you please help me how to output the text in new lines as it's original text.
Thanks for reply, i run the code it print the whole text in one line, can you please help me how to output the text in new lines as it's original text.
Please read reply #2...and #3 and #4
In short, don't use file_get_contents(), use file() or fget()
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.