Bluehost.com Web Hosting $6.95

passing the '#' character

This is a discussion on passing the '#' character within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, For years I have used a '#' character in certain strings in an application but now I find I need ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-25-2006
Peter
 
Posts: n/a
Default passing the '#' character

Hi,

For years I have used a '#' character in certain strings in an application
but now I find I need to pass those strings to a php script.
#characters seem to cut off strings
e.g. www.url.com/script.php?text=mytext#yourtext
and $text will only contain mytext
#yourtext is gone

I have changed the program and php so that a # characters are replaced by a
dash '-' and I apply the logic on that (so no problem)
but now I also need the ability to manually input the data (POST form) and
of course now the '#' is again used by those that do not know.

Besides onvious warnings in the html, can I fix this in php ?

Can I check for the '#' character ?
In my test I can't seem to do that because the #' and rest of the text are
already gone ?

Your input appreciated



Reply With Quote
  #2 (permalink)  
Old 12-25-2006
Thomas Mlynarczyk
 
Posts: n/a
Default Re: passing the '#' character

Also sprach Peter:

> For years I have used a '#' character in certain strings in an
> application but now I find I need to pass those strings to a php
> script. #characters seem to cut off strings
> e.g. www.url.com/script.php?text=mytext#yourtext
> and $text will only contain mytext
> #yourtext is gone


In your example, #yourtext would mean a fragment identifier (an anchor
within the document), which is not part of the URL (only the browser needs
it to know how far to scroll down when displaying the page).

You could escape the # (%35 or something like that) and PHP has functions to
do the encoding and decoding. See
http://de.php.net/manual/en/function.urlencode.php and related functions.

Greetings,
Thomas


Reply With Quote
  #3 (permalink)  
Old 12-26-2006
Peter
 
Posts: n/a
Default Re: passing the '#' character

> You could escape the # (%35 or something like that) and PHP has functions
> to do the encoding and decoding. See
> http://de.php.net/manual/en/function.urlencode.php and related functions.


Problem is (I think) that it's too late when I can do the checking and
decoding
because a button is clicked and the data is sent via a form ... and is the
data not lost at that point ?


Reply With Quote
  #4 (permalink)  
Old 12-26-2006
hackajar@gmail.com
 
Posts: n/a
Default Re: passing the '#' character

do a sanity check. Check if that value is even there before you send
to the other script.

Example:

$data = "#mytext";
//Note: Adding this might help:
//$data = urlencode($data);

$url = "myurl.com?text=$data";

echo $url;

-Hackajar

Peter wrote:
> > You could escape the # (%35 or something like that) and PHP has functions
> > to do the encoding and decoding. See
> > http://de.php.net/manual/en/function.urlencode.php and related functions.

>
> Problem is (I think) that it's too late when I can do the checking and
> decoding
> because a button is clicked and the data is sent via a form ... and is the
> data not lost at that point ?


Reply With Quote
  #5 (permalink)  
Old 12-26-2006
Peter
 
Posts: n/a
Default Re: passing the '#' character

> do a sanity check. Check if that value is even there before you send
> to the other script.
>
> Example:
>
> $data = "#mytext";
> //Note: Adding this might help:
> //$data = urlencode($data);
>
> $url = "myurl.com?text=$data";
>
> echo $url;


I'm sorry, but I'm still not sure how I can change or sanity-check a value
before it is sent to the other script, as it is send via an input form, like
so:


<form method="POST" action="receive_text.php">
<input type="hidden" name="send" value="true">
<input type="hidden" name="validate" value="14y22233323q">
<input type="hidden" name="manual_input" value="true">
<table style="margin-left:3px" height="100%" width="580px" cellspacing="0"
cellpadding="0" border='0'>

<tr>
<td colspan="2" class="support"
style="background-color:#EBF1F4;align:left">
blablabla ... explanation
</td>
</tr>

<tr>
<td class="support" style="background-color:#EBF1F4;align:left">
ID:
</td>
<td class="support" style="background-color:#EBF1F4;">
<input name="input_text" id="input_text" size="70" type="text">
</td>
</tr>

<tr>
<td colspan="2" class="support" style="background-color:#EBF1F4;">
<div align="center">
<input name="send_text" id="send_text" value="Send text" type="submit">
</div>
</td>
</tr>
</table>
</form>

So the end user types or copies text to the ID field and then click the Send
text button.
When receive_text.php gets the value, as far as I can see, the data after
the # is already gone.


Reply With Quote
  #6 (permalink)  
Old 12-29-2006
Peter
 
Posts: n/a
Default Re: passing the '#' character

I take it the silence means there is no solution ?
I was thinking maybe this is more something that can be fixed with
javascript


Reply With Quote
  #7 (permalink)  
Old 12-29-2006
Rik
 
Posts: n/a
Default Re: passing the '#' character

Peter wrote:
> I take it the silence means there is no solution ?
> I was thinking maybe this is more something that can be fixed with
> javascript


Well, jeah.
The hash is reserved in urls to some extend, as indicated earlier.
The only way to deliver one is to either:
- POST instead of get, in which case it shouldn't be a problem.
- urlencode() it for a GET variable.

Javascript is not a real solution, you'd either have to:
- change the value sent to the server, in which case you should change it
all together, an immidiately forget about js.
- get extra data via some murky AJAX, which is not very desirable either if
it's the only way to pass the data correctly.
--
Rik Wasmus


Reply With Quote
  #8 (permalink)  
Old 12-29-2006
Serge Terryn
 
Posts: n/a
Default Re: passing the '#' character

Peter schreef:
> Hi,
>
> For years I have used a '#' character in certain strings in an application
> but now I find I need to pass those strings to a php script.
> #characters seem to cut off strings
> e.g. www.url.com/script.php?text=mytext#yourtext
> and $text will only contain mytext
> #yourtext is gone
>
> I have changed the program and php so that a # characters are replaced by a
> dash '-' and I apply the logic on that (so no problem)
> but now I also need the ability to manually input the data (POST form) and
> of course now the '#' is again used by those that do not know.
>
> Besides onvious warnings in the html, can I fix this in php ?
>
> Can I check for the '#' character ?
> In my test I can't seem to do that because the #' and rest of the text are
> already gone ?
>
> Your input appreciated
>
>
>


Maybe : $url = 'www.url.com/script.php?text=mytext#yourtext'; // use of
single quotes.

Or with double quotes :

$url = "www.url.com/script.php?text=mytext\#yourtext";




--
Posting at the top because that's where the cursor happened to be,
is like shitting in your pants because that's where your asshole
happened to be.

http://www.essetee.be
Reply With Quote
  #9 (permalink)  
Old 12-29-2006
Michael Fesser
 
Posts: n/a
Default Re: passing the '#' character

..oO(Peter)

>I take it the silence means there is no solution ?


IMHO there's not even a problem, or I just don't see it.

Because the # is a reserved character in a URL, every browser will
automatically URL-encode it to %23 before submitting the form. I would
say there's something wrong in your receiving script. What does a

var_dump($_POST);

at the beginning of your receiving script show, when you enter something
with an octothorpe in your form?

Micha
Reply With Quote
  #10 (permalink)  
Old 12-29-2006
Peter
 
Posts: n/a
Default Re: passing the '#' character

Well I'll be ....
You're right, the data is there !!
And I now was able to fix the problem as well.

There was a small flaw in the script but when I started debugging it I
always passed the data via the URL (GET) instead of going though the pages
using POST.
Via the URL the data after the # was clearly gone so I figured that was the
issue without realising that this may be different for POST !
However, via POST the string is intact and a small fix in the script now
deals with the data correctly.

Thanks for the tip.
-------------------------------------------------------
"Michael Fesser" <netizen@gmx.de> wrote in message
news:dgiap2l8kbcp05a7kr648idunbpgholbq3@4ax.com...
> .oO(Peter)
>
>>I take it the silence means there is no solution ?

>
> IMHO there's not even a problem, or I just don't see it.
>
> Because the # is a reserved character in a URL, every browser will
> automatically URL-encode it to %23 before submitting the form. I would
> say there's something wrong in your receiving script. What does a
>
> var_dump($_POST);
>
> at the beginning of your receiving script show, when you enter something
> with an octothorpe in your form?
>
> Micha
>



Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:33 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0