RE: [PHP] replacing & but not special chars

2003-07-28 Thread Jeff Harris
On Jul 28, 2003, "Ford, Mike   [LSS]" claimed that:

|> -Original Message-
|> From: Shawn McKenzie [mailto:[EMAIL PROTECTED]
|> Sent: 27 July 2003 08:36
|>
|> I have some URLs in hrefs that have an &.  This does not
|> validate HTM4.01
|> transitional, so I want to replace them with &
|>
|> So I buffer the output and do a replace, but suppose there is
|> already an
|> & then I get & or if I have anything else like
|> " then I get
|> "
|
|Why can't you just put & in the href string?  Seems like the simplest
|way to me.
|
|Cheers!
|
|Mike
|-
|Mike Ford,  Electronic Information Services Adviser,

Thus sayeth the manual,
"Note: Be careful about variables that may match HTML entities. Things
like &, © and £ are parsed by the browser and the actual
entity is used instead of the desired variable name. This is an obvious
hassle that the W3C has been telling people about for years. The reference
is here: http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2 PHP
supports changing the argument separator to the W3C-suggested semi-colon
through the arg_separator .ini directive. Unfortunately most user agents
do not send form data in this semi-colon separated format. A more portable
way around this is to use & instead of & as the separator. You don't
need to change PHP's arg_separator for this. Leave it as &, but simply
encode your URLs using htmlentities()(urlencode($data)). Example 2.
urlencode() and htmlentities() example

echo '';
"
This is the word of PHP.

Therefor, if _you_ are constructing the query strings, you can change your
arg_separator (arg_separator.output, PHP_INI_ALL; arg_separator.input,
PHP_INI_SYSTEM|PHP_INI_PERDIR) setting and in code, then you should be
able to use & OR, change your & to something else, like ; before you
send it, then change it back when you $_GET it.

Jeff
-- 
Registered Linux user #304026.
"lynx -source http://jharris.rallycentral.us/jharris.asc | gpg --import"
Key fingerprint = 52FC 20BD 025A 8C13 5FC6  68C6 9CF9 46C2 B089 0FED
Responses to this message should conform to RFC 1855.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] replacing & but not special chars

2003-07-28 Thread Ford, Mike [LSS]
> -Original Message-
> From: Shawn McKenzie [mailto:[EMAIL PROTECTED]
> Sent: 27 July 2003 08:36
> 
> I have some URLs in hrefs that have an &.  This does not 
> validate HTM4.01
> transitional, so I want to replace them with &
> 
> So I buffer the output and do a replace, but suppose there is 
> already an
> & then I get & or if I have anything else like 
> " then I get
> "

Why can't you just put & in the href string?  Seems like the simplest
way to me.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] replacing & but not special chars

2003-07-27 Thread Andrew Brampton
How about you decode the string, and then encode it like so:
$decode = html_entity_decode($input);
$output = htmlentities($decode);

If you have the string
ab&something&blah
the decode will turn that into
ab&something&blah
and then encode it into
ab&something&blah

This can run into problems, but they will be just the same problems you
would receive with any other method... The problem I speak of is when your
input string is "something&" and & isn't a HTML Entity but the
proper string just so happened to have a & in it just before the amp... In
that case the amp; would be incorrectly removed... However the chances of
having a string that matches a HTML entity with a "bad" & placed in front of
it are so high that you shouldn't worry (and you did mention it was a URL,
so as far as I know ; can't appear in a valid URL, so I don't think you
should worry at all :))... And if you are worrying then any method you chose
will have this problem and you should do the task by hand :)

Hope this helps
Andrew

- Original Message -
From: "Shawn McKenzie" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, July 27, 2003 8:36 AM
Subject: [PHP] replacing & but not special chars


> I have some URLs in hrefs that have an &.  This does not validate HTM4.01
> transitional, so I want to replace them with &
>
> So I buffer the output and do a replace, but suppose there is already an
> & then I get & or if I have anything else like " then I
get
> "
>
> Any ideas on how to do this the right way???
>
> Thanks!
> Shawn
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php