PDA

View Full Version : removing links from textblocks with PHP



Cheap Bastard
June 13th, 2001, 15:08
subject's pretty selfexplanatory...
(remember, in PHP)

what i would like is (for a very very simple script) to have people submit a textblock (with some extra stuff like name and maybe a few extra fields) and then let the script display all submittions.

1) no moderated posts or anything (at least, not yet)
2) i don't want any links in there (there's some other tags i wouldn't want, like iframe and stuff). How could you

either
a) take out individual tags
or
b) disable all HTML tags

(whatever's the easiest, don't need both)

thanks

puDDs
June 13th, 2001, 22:36
Both are easy, but not sure of the exact syntax for PHP....for ASP it would be:



'for all html:

dim content, newstring
content = "<b>the actual content</b>"
newstring = Replace(content, "<", "&lt;")
newstring = Replace(content, ">", "&gt;")

'for say, the <b> tag...

dim content, newstring
content = "<b>the actual content</b>"
newstring = Replace(content, "<b>", "&lt;b&gt;")
newstring = Replace(content, "</b>", "&lt;/b&gt;")


Of course, that's asp...but it shouldn't be hard to interpret...and there must be something in PHP analagous to the "Replace" function. Just find that, and use it the same way I did....

Cheap Bastard
June 14th, 2001, 00:08
wouldn't there be anything to just remove everything between < and > characters?
just removing all tags, isn't there some kind of built-in function?

lucifer
June 14th, 2001, 03:53
$stuff="<B>whatever</B>";
$stuff=strip_tags($stuff);


you can get it to leave tags you allow see docs.

Cheap Bastard
June 14th, 2001, 09:21
there seems to be some confusion on the php site
http://www.php.net/manual/en/function.strip-tags.php
(i checked my book but it's not in there)

if you want both the opening tags and closing tags of say, <i> and </i> to stay, do you have to

$stuff = strip_tags($stuff,"<i>,</i>")
or just
$stuff = strip_tags($stuff,"<i>")

lucifer
June 14th, 2001, 11:55
experiment but I go for the one with less typing :)

Cheap Bastard
June 14th, 2001, 12:17
<?
$msg = "Yes, it's <B>all</b> that and more, a <i>lot<b> more</b></i> than that. <a href=\"http://www.phoenix0.com\" target=_blank><u>phoenix0.com</u></a>";
$msg = strip_tags($msg,"<I>,<U>");
?>

<html><head><title>test</title></head><body><? echo "$msg"; ?></body></html>
produced


<html><head><title>test</title></head><body>Yes, it's all that and more, a <i>lot more</i> than that. <u>phoenix0.com</u></body></html>