www.webdeveloper.com
Results 1 to 7 of 7

Thread: Problems with echo statement

  1. #1
    Join Date
    Feb 2012
    Posts
    102

    Question Problems with echo statement

    Hello,

    I am having an issue with an echo statement.

    I am passing a string with $_GET and attempting to print it with echo. The issue is the content in the $_GET contains an & and when I echo the string it doesnt print the & or anything after it. For example,

    the url which is sending the information is

    PHP Code:
    http://www.realitytvaddict.com/read_post.php?tid=35&name=The%20Kardashians&subject=Kim%20&%20Kanye!%20Will%20it%20last?#1677 
    I have tried just echoing the $_GET['subject']. I have also tried running it through htmlspecialchars(). I have also tried replacing the & with regrex but nothing seems to work.

    Whenever I print out the variable it is turned from "Kim & Kanye! Will it last?" into "Kim"

    Can anyone figure out why it is doing this?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,333
    Either use htmlspecialchars() or htmlentities() on the text being output.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Feb 2012
    Posts
    102
    Tried htmlspecialchars, ended up with the same effect. Thats what I thought would fix the problem as well.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,333
    We may need to see a bit of the actual PHP code to better understand what you are trying to do. Maybe it's just a case of a HTML tag attribute's value not being quoted?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Feb 2012
    Posts
    102
    Figured it out. Just needed to add urlencode() to the variable before it was passed via $_GET. That allows the & to get passed and then I used htmlentitites() on the receiving end before echoing.

  6. #6
    Join Date
    Oct 2012
    Posts
    3
    Can you post a tidbit of the code and I may be able to help you!

  7. #7
    Join Date
    Oct 2012
    Posts
    8
    plz attach your code and i may be able to help u

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles