PDA

Click to See Complete Forum and Search --> : Disable code in a section?



-AJRAD-
11-28-2006, 04:00 PM
I'm making a thingy where you input some stuff in a form, and it saves it to a file to open it into a HTML-enabled dynamic text box in flash.
I don't want people putting custom HTML code in it though. How do I format it so anything in there comes out as pure text (but allow bold colour italic etc!)

catbert303
11-29-2006, 06:15 AM
If you're using PHP to write the file you could try using the strip_tags function to clean out unwanted HTML,

$cleanedString = strip_tags($theTextWithHtmlTags, '<b><i><font>');

should remove any HTML tags except <b>, <i> and <font>

-AJRAD-
11-29-2006, 12:22 PM
no i mean reading into the flash lol from a variable. uses the htmltext thing in flash.

Frets
11-29-2006, 01:27 PM
I'm sorry but this is not making sense.
If your making it to write a .txt then you must be making it in a server side program.
hence... catbert303 has already provided a solution to strip the tags.

If you want tags stripped before they are displayed in the swf .... well
we do have flash forums for that.

-AJRAD-
11-29-2006, 03:49 PM
im not WRITING to a txt. im loading a string from one. the string is in html. the writing ive got working, the user is able to enter html though - i just need to know a html tag or something that i can put round the string to disable certain code.

yasunobu13
11-30-2006, 01:31 AM
im not WRITING to a txt. im loading a string from one. the string is in html. the writing ive got working, the user is able to enter html though - i just need to know a html tag or something that i can put round the string to disable certain code.
I think they understand. You started off with:

I'm making a thingy where you input some stuff in a form, and it saves it to a file...
What they are trying to say is to do your filtering when the user submits the form. If you use PHP to handle the form and save to a file, then you have much more powerful, built-in tools to strip out unwanted HTML tags than you would in Flash.

catbert303
11-30-2006, 11:51 AM
I don't know, if you are doing this in flash does actionscript support regular expressions yet? (I'm a few versions behind) If so you could perhaps use them to filter the text.

If not and you know the content in the file would be well formed XHTML you could use the XML object in Flash to help clean up the HTML - here is a very rough example (maybe need some work):



// a test string of HTML to work with
var src = '<b>Hello <span>world</span></b><i>This is a test <font color="#ff00ff">test!</font></i> <a href="#" class="some-class">a link</a>';
// the tags and attributes to allow
var allowedTags = {b: 1, i: 1, font: 1, a: 1};
var allowedAttrs = {color: 1, href: 1};

// create an XML object
var x = new XML("<root>" + src + "</root>");

function buildString(node) {
var str = "";

if (node.nodeType == 3) { // if it's a text node just add it to the string
str += node.nodeValue;
} else if (allowedTags[node.nodeName.toLowerCase()]) { // the tag is allowed
str += "<" + node.nodeName;
for (var a in node.attributes) { // add any allowed attributes
if (allowedAttrs[a]) {
str += " " + a + '="' + node.attributes[a] + '"';
}
}
str += ">";
}

if (node.hasChildNodes) {
for (var i = 0; i < node.childNodes.length; ++i) {
str += buildString(node.childNodes[i]);
}
}
if (allowedTags[node.nodeName.toLowerCase()]) {
str += "</" + node.nodeName + ">";
}
return str;
}

str = buildString(x.firstChild);
trace(src);
trace(str);


Doing all this on the server side with PHP when the file is saved would definitely be easier :)