strange behavior for # sign

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wpsd2006
Forum Commoner
Posts: 66
Joined: Wed Jan 07, 2009 12:43 am

strange behavior for # sign

Post by wpsd2006 »

I created a form text area here

Code: Select all

 
<textarea id="notes"></textarea>
<input type="button" onclick="sendtext()" />
 
This is the javascript i'm using javascript prototype well you can care less about this
it's working 100% at this point

Code: Select all

 
function sendtext() {
alert($('notes').innerHTML); // the first alert the content of the notes before sending the data with ajax
new Ajax.Request ('ajax_notes.php',{
method: 'post',
parameters: 'v='+$('notes').innerHTML,
onComplete: function(resp) {
alert(resp.responseText) //It will alert the text on complete which is the text inside the text area
}
});
}
 
now this is the ajax_notes.php

Code: Select all

 
print_r($_POST);
 
Ok now when i submit the data like below

example 1
textarea: abcdefghijklmnopqrstu
1 alert: abcdefghijklmnopqrstu
2 alert: abcdefghijklmnopqrstu

example 2
textarea: abca###abc
1 alert: abca###abc
2 alert: abca

example 3
textarea: ###
1 alert: ###
2 alert:

now this is really strange behavior it seems the $_POST can't get the '#' string it delete the string that start with #
like example number 2
anyone ever get this problem
i don't know this is javascript problem or the php because on the 1st alert i still get the correct value even if it begin with ###
wpsd2006
Forum Commoner
Posts: 66
Joined: Wed Jan 07, 2009 12:43 am

Re: strange behavior for # sign

Post by wpsd2006 »

looks it's javascript problem or maybe the php

when i change the # to %23 php parse it normal and get the # correctly
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: strange behavior for # sign

Post by Benjamin »

The # character is used to denote/specify an anchor in URIs so it does need to be converted into an entity. It's also used to denote the beginning of a comment line in PHP.
Post Reply