SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Location
    Idaho
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Passing a newline character from a textbox to a php script

    I recently built a small page that has a text box, when the user types stuff in the text box the image of that text appears below it. The image is created with PHP using the GD image library. The text is passing to it using the get method. It works all fine and dandy, but I would like it to create a newline in the image when a newline is created in the text box. Right now when you press enter it just adds a space and keeps going on the same line. I was wondering how I could successfully pass a newline character to the php script. I was also wondering how I could encode all the special characters (like # % $) so they don't get parsed by the script. Is there an easy function is JS to do this? I know there is in PHP but I can't figure out how to encode them before they are sent to the script if I were to use PHP. Any help would be great thanks! Here is the code for the page:

    Code:
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script type="text/javascript">
    
    function preview(event)
    {
    	txt=document.getElementById("input").value;
    	
    	var Url = "font.php?text=" + txt;
    	document.getElementById("img").src=Url;
    }
    </script>
    </head>
    
    <body onload="preview();">
    <form name="text_preview">
    <textarea id="input" cols="60" rows="20" onkeyup="preview(event);" >Preview Text!</textarea>
    <div id="img_container" style="overflow:auto; width: 800px; height: 400px; border: 1px solid black;">
    <img src="font.php?text=" id="img" />
    </div>
    
    </form>
    
    </body>
    </html>

  2. #2
    SitePoint Zealot
    Join Date
    Aug 2008
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try using 'escape' function
    it produce url-encoded string, so

    document.getElementById("img").src=escape(Url);

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2008
    Location
    Idaho
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Perfect! That's exactly what I needed. Thank you!


Bookmarks

Posting Permissions

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