DHTML Forum  

Go Back   DHTML Forum > dhtmlcentral.com > Off-topic
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #11  
Old 04.02.2004, 08:37
Mark Mark is offline
Erfahrener Benutzer
 
Join Date: 28.02.2002
Location: Netherlands
Posts: 2.853
Default

Syedur is on a PHP server, Abhi.

Try this:
[code:zcy2uwiiyz]
<?php // begin of page
function validXHTML($buffer){
$buffer = str_replace("&", "&amp;", $buffer);
$buffer = str_replace("\"", "&quote;", $buffer);
return $buffer;
}
ob_start("validXHTML");
?>
[/code:zcy2uwiiyz]
The output of the page goes through validXHTML(), where & and " are replaced. Then the buffer is returned and send to the client.

Disclaimer: I haven't tested this.. but I'm pretty confident it'll work

- [url="http://neo.dzygn.com/"]Mark[/url:zcy2uwiiyz]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12  
Old 04.02.2004, 09:19
Abhi Abhi is offline
Erfahrener Benutzer
 
Join Date: 13.07.2001
Location: India
Posts: 1.626
Default

hehe, yea I know (serverside). I misunderstood his or anyone else to an example.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13  
Old 04.02.2004, 14:37
Syedur Syedur is offline
Erfahrener Benutzer
 
Join Date: 12.05.2001
Location: USA
Posts: 347
Default

<blockquote id="quote"><span class="smalltext" id="quote">quote:<hr id="quote">Originally posted by Mark

Syedur is on a PHP server, Abhi.

Try this:
[code:gxieilumm6]
<?php // begin of page
function validXHTML($buffer){
$buffer = str_replace("&", "&", $buffer);
$buffer = str_replace("\"", ""e;", $buffer);
return $buffer;
}
ob_start("validXHTML");
?>
[/code:gxieilumm6]
The output of the page goes through validXHTML(), where & and " are replaced. Then the buffer is returned and send to the client.

Disclaimer: I haven't tested this.. but I'm pretty confident it'll work

- [url="http://neo.dzygn.com/"]Mark[/url:gxieilumm6]
<hr id="quote"></blockquote id="quote"></span id="quote">

Parse Error on line 4... which is "return $buffer;"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14  
Old 04.02.2004, 14:48
Mark Mark is offline
Erfahrener Benutzer
 
Join Date: 28.02.2002
Location: Netherlands
Posts: 2.853
Default

Odd, it works fine on my system.

By the way, the forum software interpreted one part of the code wrong, I've updated my post now.

- [url="http://neo.dzygn.com/"]Mark[/url:6mh4nc16vy]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15  
Old 04.02.2004, 15:41
hzr hzr is offline
Erfahrener Benutzer
 
Join Date: 16.07.2001
Location: Sweden
Posts: 1.110
Default

<blockquote id="quote"><span class="smalltext" id="quote">quote:<hr id="quote">$buffer = str_replace("\"", "&quote;", $buffer);<hr id="quote"></blockquote id="quote"></span id="quote">
Actually, " (quotation mark) does't have to be written as &quot; (not &quote, if it's not in an attribute value of course.
You didn't include < though Mark, so the code should probably look something like this (kept the "):
[code:58etbbgoe4]
<?php // begin of page
function validXHTML($buffer){
$buffer = str_replace("&", "&amp;", $buffer);
$buffer = str_replace("\"", "&quot;", $buffer);
$buffer = str_replace("<", "&lt;", $buffer);
return $buffer;
}
ob_start("validXHTML");
?>

[/code:58etbbgoe4]

<font face="Courier New">--
David</font id="Courier New">
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16  
Old 04.02.2004, 17:19
Tim Scarfe Tim Scarfe is offline
Erfahrener Benutzer
 
Join Date: 14.05.2001
Location: United Kingdom
Posts: 1.015
Default

<blockquote id="quote"><span class="smalltext" id="quote">quote:<hr id="quote">How would that help? If I understand Syedur right, he's having problems with '&' and '<' which has to be encoded as e.g. & and < repectively. But this has to be done in HTML too.<hr id="quote"></blockquote id="quote"></span id="quote">

No.

http://validator.w3.org/check?uri=ht...om%2Ftest.aspx

Sorry but HTML is fine for your needs, gratuitous abuse of XHTML is nothing more than a waste of your time. Unless of course, you like wasting your time.

<blockquote id="quote"><span class="smalltext" id="quote">quote:<hr id="quote">
function validXHTML($buffer){
$buffer = str_replace("&", "&", $buffer);
$buffer = str_replace("\"", """, $buffer);
$buffer = str_replace("<", "<", $buffer);
return $buffer;
}
ob_start("validXHTML");
<hr id="quote"></blockquote id="quote"></span id="quote">

Do you really want to shag the performance and cachability of your page with code like that?

--
Regards,
Tim Scarfe <tim@developer-x.com>
http://www.developer-x.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17  
Old 04.02.2004, 17:38
hzr hzr is offline
Erfahrener Benutzer
 
Join Date: 16.07.2001
Location: Sweden
Posts: 1.110
Default

<blockquote id="quote"><span class="smalltext" id="quote">quote:<hr id="quote">No.<hr id="quote"></blockquote id="quote"></span id="quote">
Well, they don't have to be escaped always, but '<' and '&' have special meaning in HTML (and you know for what). Try something like
[code:9buqeh3fnx]
x&y
a<b
[/code:9buqeh3fnx]
<blockquote id="quote"><span class="smalltext" id="quote">quote:<hr id="quote">Do you really want to shag the performance and cachability of your page with code like that?<hr id="quote"></blockquote id="quote"></span id="quote">
Blame it on Mark , I only modified his code.

<font face="Courier New">--
David</font id="Courier New">
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18  
Old 04.02.2004, 22:18
Tim Scarfe Tim Scarfe is offline
Erfahrener Benutzer
 
Join Date: 14.05.2001
Location: United Kingdom
Posts: 1.015
Default

Well I don't have an axe to grind man, but so many people abuse XHTML (like Flash heh).

--
Regards,
Tim Scarfe <tim@developer-x.com>
http://www.developer-x.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #19  
Old 05.02.2004, 00:46
Syedur Syedur is offline
Erfahrener Benutzer
 
Join Date: 12.05.2001
Location: USA
Posts: 347
Default

what is abuse of XHTML to you?
What do you think the purpose of it? How do you think people misuse it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #20  
Old 05.02.2004, 01:01
starlight starlight is offline
Erfahrener Benutzer
 
Join Date: 17.07.2002
Location:
Posts: 630
Default

<blockquote id="quote"><span class="smalltext" id="quote">quote:<hr id="quote">
But, what if the content is dynamic and it is being generated via something else; server side and such. what do I do then?
<hr id="quote"></blockquote id="quote"></span id="quote">
Is it hard to generate directly escaped data?
<blockquote id="quote"><span class="smalltext" id="quote">quote:<hr id="quote">
No.
http://validator.w3.org/check?uri=ht...om%2Ftest.aspx
<hr id="quote"></blockquote id="quote"></span id="quote">
David is right, Tim.
You can do the same in xhtml and get only a *very* tiny warning:
[code:ky8eomwq3k]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<body>
<div>
x & y
a < b
</div>
</body>
</html>
[/code:ky8eomwq3k]
as far as you dont write:
[code:ky8eomwq3k]
x&y
a<b
[/code:ky8eomwq3k]
funny stuff..

--
Chris
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

All times are GMT +2. The time now is 03:45.


Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.