Safe for storage...

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
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Safe for storage...

Post by Todd_Z »

I want to store strings in a file which are safe for html viewing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into &gt; and &lt;
What to do? What to do?str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into &gt; and &lt;
What to do? What to do?ae]
function safeStore ( $str ) {
$str = strip_tags( $str, "<b><i><u><a>" );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into &gt; and &ampquote; );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?c3bebaae]

This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do? Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, &quote;&lt;b><i><u>&rings in a file which are safe for html viewing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?n tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a"&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;a&gt;" );
$str = between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?een tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? Wha


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?t;
What to do? What to do?ll characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?ing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?on safeStore ( $str ) {
$str = strip_tags( $str, "<b><i><u><a>&quote; );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into &p;amp;lt;u><a>" );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?" );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags ( viewing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES )p;amp;gt;<i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviop;quote;<b><i><u><a&gt;&quote; );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?aae]
function safeStore ( $str ) {
$str = strip_tags( $str, &quote;&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;a&gt;&quote; );
$str = stripslashes( $str )ich are safe for html viewing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?t;b><i><u><a>" );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?wing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do? viewing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?which are safe for html viewing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, &quote;&lt;b&gt;&lt;i&gt;&lt;u>&ltin a file which are safe for html viewing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, &quote;&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;a&gt;&quote; );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the g.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, &quote;&lt;b&gt;&lt;i&gt;&lt;u&gt;&lt;a&gt;&quote; );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into &gt; and &lt;
What to do? Wha_tags( $str, "<b><i><u><a>" );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?rings in a file which are safe for html viewing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?fe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?rings in a file which are safe for html viewing.

Criteria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into &amp a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
s( $str, "<b><i><u><a>" );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?><a>" );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?cause the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?ria:
Safe Tags: b, i, u, a
Escape all characters possible between tags.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
[/php:1:cdc3be.

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return htmlentities( $str, ENT_QUOTES );
}
This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?amp;lt;u><a>" );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
Whap;quote;<b><i><u><a>" );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?shes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into > and <
What to do? What to do?$str, "<b><i>&lt;u&gt;&lt;a&gt;&quote; );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}



function safeStore ( $str ) {
$str = strip_tags( $str, "<b><i><u><a>" );
$str = stripslashes( $str );
return htmlentities( $str, ENT_QUOTES );
}


This fails obviously because the remaining tags (b,i,u,a) are escaped into &gt; and &lt;
What to do? What to do?
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

not sure what you mean?

you mean you want to strip out all of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i"; with .*?>/i";

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should e pattern....weirdness it should end with .*?>/i";s like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/<(i|u|b|a).*?>/i";
edit: whoa! it mean?

you mean you want to strip out all of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i"; just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/&lt;(i|u|b|a).*?&gt;/i&quote;;
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";tern "/&lt;(i|u|b|a).*?&gt;/i&quote;;


edit: whoa! it cut off the end of my pattern.. become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/&lt;(i|u|b|a).*?&gt;/i&quote;;
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";me just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";h:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";ou'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pae;;


edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";of my pattern....weirdness it should end with .*?>/i"; all of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";t;(i|u|b|a).*?>/i";


edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";n "/<(i|u|b|a).*?>/i";


edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";

if so, you'll need a regex to do it.

Code: Select all

$pattern &amyou want to strip out all of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/&lt;(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";;amp;lt;(i|u|b|a).*?>/i";


edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i"; of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/&lt;(i|u|b|a).*?&gt;/i&quote;;
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i"; all of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/&lt;(i|u|b|a).*?&gt;/i&quote;;
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";n you want to strip out all of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/&lt;(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";mp;lt;i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/&lt;(i|u|b|a).*?&gt;/i&quote;;
edit: whoa! it cu

you mean you want to strip out all of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/&lt;(i|u|b|a).*?&gt;/i&quote;;
the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i"; <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/&lt;(i|u|b|a).*?&gt;/i&quote;;
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?&amptested]
$pattern "/<(i|u|b|a).*?>/i";


edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";mean?

you mean you want to strip out all of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";ags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";mean?

you mean you want to strip out all of the stuff in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern &quote;/&lt;(i|u|b|a).*?&gt;/i&quote;;
edit: whoa! it cut off the end of my pattern..i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my patteed]
$pattern "/<(i|u|b|a).*?>/i";


edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";]

edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";in the tags like <i style="blah:bling"> would become just <i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";<i>??

if so, you'll need a regex to do it.

Code: Select all

$pattern "/<(i|u|b|a).*?>/i";
edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";;


edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";n "/<(i|u|b|a).*?>/i";


edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";uld end with .*?>/i";
$pattern "/<(i|u|b|a).*?>/i";


edit: whoa! it cut off the end of my pattern....weirdness it should end with .*?>/i";
User avatar
delorian
Forum Contributor
Posts: 223
Joined: Sun May 04, 2003 5:20 pm
Location: Olsztyn, Poland

Post by delorian »

Like Buritto said you could use a regular expression:

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}
But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?quote;, "<$1>&quote;, $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?;gt;<i><u><a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i&quote;, &quote;&lt;$1&gt;&quote;, $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff? safeStore ( $str ) {
$str = strip_tags( $str, "<b><i&gt;&lt;u&gt;&lt;a&gt;" );
$str = stripslashes( $str );
return preg_replace(&quotyou could use a regular expression:

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}
But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?uote;<b><i><u><a>&quote; );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if itlt;a>&quote; );
$str = stripslashes( $str );
return preg_replace(&quote;#&lt;(i|b|u|a).*?CLEAR_THAT&gt;#i&amp "<b><i&gt;&lt;u&gt;&lt;a&gt;&quote; );
$str = stripslashes( $str );
return preg_replace(&quote;#&lt;(i|b|u|a).*?CLEAR_THAT&gt;#i&quote;, &quote;&lt;$1&gt;&quote;, $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?;quote;<b><i><u><a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignoe;, $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?t's with that *ignorance is bliss* stuff?tr = strip_tags( $str, "<b><i><u><a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?1]
function safeStore ( $str ) {
$str = strip_tags( $str, &quote;&lt;b&gt;&lt;i&gt;&lt;u><a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?p;lt;i><u><a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT&gt;#i&quote;, &quote;&lt;$1&gt;&quote;, $str);
}


But then why do you allow anchor tag if it is going to be empty after all.
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT&gt;#i&quote;, &quote;&lt;$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor ta

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>&amp );
  $str = stripslashes( $str );
  return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}
Bua>" );
$str = stripslashes( $str );
return preg_replace("#&lt;(i|b|u|a).*?CLEAR_THAT&gt;#i&quote;, "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?stuff?p;gt;<i><u><a&gt;&quote; );
$str = stripslashes( $str );
return preg_replace(&quote;#&lt;(i|b|u|a).*?CLEAR_THAT&gt;#i&quote;, &quote;gular expression:

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}
But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?quote; );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?]
function safeStore ( $str ) {
$str = strip_tags( $str, "<b><i>&lt;u&gt;<a&gt;&quote; );
$str = stripslashes( $str );
return preg_replace(&quote;#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}
But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?regular expression:

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}
But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?p;amp;lt;b><i&gt;&lt;u&gt;&lt;a&gt;&quote; );
$str = stripslashes( $str );
return preg_replace("uld use a regular expression:

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}
But then why do you allow anchor 237e2ec3ac]
function safeStore ( $str ) {
$str = strip_tags( $str, "<b><i><u><a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1&atore ( $str ) {
$str = strip_tags( $str, "<b><i><u>&lt;a&gt;&quote; );
$str = stripslashes( $str );
return preg_replace(&quote;#&lt;(i|b|u|a).*?CLEAR_THAT&gt;#i&quote;, &quote;&lt;$1&gt;&quote;, $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss;gt;<a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?you could use a regular expression:

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}
But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?on safeStore ( $str ) {
$str = strip_tags( $str, "<b><i><u><a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?you could use a regular expression:

Code: Select all

function safeStore ( $str ) {
  $str = strip_tags( $str, "<b><i><u><a>" );
  $str = stripslashes( $str );
  return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}
But then why do you allow anchor tag if it is going to be empty after all.


BTWtr ) {
$str = strip_tags( $str, "<b><i><u><a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT&gt;#i&quote;, &quote;&lt;$1&gt;&quote;, $str);
}

<a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?reg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?
function safeStore ( $str ) {
$str = strip_tags( $str, "<b><i><u><a>" );
$str = stripslashes( $str );
return preg_replace("#<(i|b|u|a).*?CLEAR_THAT>#i", "<$1>", $str);
}


But then why do you allow anchor tag if it is going to be empty after all.


BTW: What's with that *ignorance is bliss* stuff?
User avatar
Todd_Z
Forum Regular
Posts: 708
Joined: Thu Nov 25, 2004 9:53 pm
Location: U Michigan

Post by Todd_Z »

No No, I don't mean that at all.

Lets say i have a conversation:

Code: Select all

Hello <b>Joe's</b> Pizza. <table></td> www.google.com <div />!! Webmaster@acdrifter.com
I want that to be turned into:

Code: Select all

Hello <b>Joe&CODE;s</b> Pizza.  <a href=&quote;http://www.google.com&quote;>www.google.com</a>!! <a href=
&quote;mailto:Webmaster@acdrifter.com&quote;>Webmaster@acdrifter.com</a>
Sorry for being vague
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

I still think regex is the way to go, just pick the tags you dont' want changed and strip them out, then use htmlentities or the like to change all the others.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

You're going to have a lot of work on your hands.

Probably the order you're going to want to do stuff is:
  • Call htmlentities() on the whole string
  • Convert <b> back into <b> and so on
  • Convert web addresses to be wrapped in <a></a> tags. The big problem here is determining what a valid URI is (http://www.google.com, google.com, http://google.com, and google.com/blah_path/blah_page) are all legitimate URIs (Also note: of all the addresses I entered, phpBB only turned http://google.com into a link). There's probably a regex out there somewhere that'll find this for you. If not, either a) roll your own or b) require all URI's to begin with http://, then just use that as your delimiter
  • Convert all emails into links. This is much easier - I know there are regex's out there for finding legitimate email addresses.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply