Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy GD Library Phantom Line Break Issue

    Hi everyone.

    I am told that somebody here might be able to offer some advice on an problem I have with some GD Library code.

    I have some php code that generates two names, which I then reference in the gd script to output the two names onto an image.

    The problem is that there is a line break magically appearing after the first name.

    The code for the names is this:

    $name = "$first_array[$arnd] $second_array[$nrnd]";

    I then insert these into the gd library code as this:

    imagettftext ($im, 20, 0, 150, 150, $color, $font, $name);

    From experiments, it seems to be something to do with the [$arnd] part immediately following the $first_array which is causing the line break.

    Is there any way to force the text onto one single line, or another way to get around the problem?

    Best regards.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    trim it first:
    PHP Code:
    $name trim($first_array[$arnd]) . ' ' .  trim($second_array[$nrnd]); 
    I'm assuming the problem is that the $arr[$arnd] or $arr[$nrnd] keys contain newlines. I'd need to see those to determine that, but I doubt that the GD is adding a newline. Its possible that somewhere you're line wrapping, but the GD doesn't do that by default.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #3
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    The two files they read from are each a list of names in this format


    Name1
    Name2
    Name3
    Name4

    and so on...

    When I run the script without GD Library and just echo the result i.e.

    $name = "$first_array[$arnd] $second_array[$nrnd]";

    echo "$name";

    it all appears on the same line.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Browsers ignore whitespace. Check the source code, if it shows each on its own item then you've got the newlines.

    File handling with the file() function will preserve the newline of each item, unless you've got a new version of PHP and are adding FILE_IGNORE_NEW_LINES. I'd say it sounds pretty good like thats where you're problem is coming from.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #5
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for your help on this.

    Apologies, I'm fairly new to PHP.

    Would you be able to show an example of how I'd implement that function into the code ?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    By using file?
    PHP Code:
    $aFileLines file('/path/to/file.txt'FILE_IGNORE_NEW_LINES FILE_SKIP_EMPTY_LINES); 
    This would populate an array with each line of a file representing each element of an array. It will strip off the newline and skip any empty lines. To do this old school, you'd do:
    PHP Code:
    $aFileLines file('/path/to/file.txt');
    array_map($aFileLines'trim'); 
    Doesn't delete empty items though.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    JohnnyCashpoint (12-08-2008)

  • #7
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks very much Fou-Lu

    That was a great help


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •