SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    May 2011
    Posts
    191
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    URLencode and URLdecode

    Good day,

    I am developing a bookstore website, and I am having a little issue using URLencode and URLdecode.
    The website offers to the customers a list of books, and the customers select what they want to purchase.
    I load in a variable the list of names for all selected books, for e-mailing them to the customer after the purchase.
    The problem is in the e-mail the books are listed one by one, instead of one per line, as I desire:

    Current situation:
    Here the list of books you have purchased:
    book1 book2 book3 book4

    Desired situation:
    Here the list of books you have purchased:
    book1
    book2
    book3
    book4

    The code
    In the webpage where the books are selected:

    Initial definition for variable to load the books list:
    $Purchased_Books = "Libros adquiridos\n";

    Loading books in the variable (loop loads book name per each selected book)
    $Purchased_Books .= $rows[$valor][1]."\n";

    $URLPurchased_Books = urlencode($Purchased_Books);

    Pass the variable to the next webpage, where the e-mail is sent:
    <input type="hidden" name="Purchased_Books" value=<?php echo $URLPurchased_Books; ?> >


    In the webpage where the e-mail is sent:
    $Decoded_Purchased_Books = urldecode($URLPurchased_Books);

    Adding the book list to the e-mail:
    $message_body .= "Libros adquiridos: " .$Decoded_Purchased_Books. "\n";


    Thanks a lot!!!

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2003
    Location
    Perth W.A.
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Each time your loop runs you need to effectively parse a carriage return/ line feed. Clearly this is not happening.
    Maybe there is a conflict between URLencode and/or URLdecode and your line feed syntax (\n) or perhaps PHP's troublesome MagicQuotes function has thrown a spanner in the works!
    Maybe at this point ->
    PHP Code:
    $Purchased_Books "Libros adquiridos\n"
    try substituting a <br /> tag immediately after adquiridos.

    Just a thought

  3. #3
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Just use a different separator, like a pipe (|), no need to force yourself to use a newline


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
  •