<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>strip_tags &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/strip_tags/</link>
	<description>Feed of posts on WordPress.com tagged "strip_tags"</description>
	<pubDate>Mon, 30 Nov 2009 17:36:45 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[PHP XSS atakları ve Türkçe Karakter Problemi]]></title>
<link>http://canerblt.wordpress.com/2009/06/23/php-xss-ataklari-ve-turkce-karakter-problemi/</link>
<pubDate>Tue, 23 Jun 2009 19:48:26 +0000</pubDate>
<dc:creator>canerblt</dc:creator>
<guid>http://canerblt.wordpress.com/2009/06/23/php-xss-ataklari-ve-turkce-karakter-problemi/</guid>
<description><![CDATA[PHP Bir önceki yazımda XSS ataklarını engellemek için htmlentities() ve html_entity_decode() fonksiy]]></description>
<content:encoded><![CDATA[PHP Bir önceki yazımda XSS ataklarını engellemek için htmlentities() ve html_entity_decode() fonksiy]]></content:encoded>
</item>
<item>
<title><![CDATA[Fun With RegEx - Part 1]]></title>
<link>http://rickyrobinett.wordpress.com/2009/02/02/fun-with-regex-part-1/</link>
<pubDate>Mon, 02 Feb 2009 09:00:08 +0000</pubDate>
<dc:creator>rickyrobinett</dc:creator>
<guid>http://rickyrobinett.wordpress.com/2009/02/02/fun-with-regex-part-1/</guid>
<description><![CDATA[During the preparation for my Zend Certification, I found Regular Expressions to be one of those top]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>During the preparation for my Zend Certification, I found Regular Expressions to be one of those topics that I had a difficult time wrapping my head around. Recently, due to a project at work, I have been exploring the power of RegEx. Throughout my research, I&#8217;ve found some pretty cool expressions, as well as some very useful tools.</p>
<p><strong>Removing All HTML Tags</strong></p>
<p>Unlike PHP, ColdFusion does not have a strip_tags function. Luckily, as I discovered, the RegEx to strip HTML tags is not complicated.</p>
<pre>&#60;cfscript&#62;
content = '&#60;div&#62;Tacos&#60;/div&#62;&#60;div&#62;Burritos&#60;/div&#62;&#60;div&#62;Tostadas&#60;/div&#62;';
content = REReplaceNoCase(content,'&#60;[^&#62;]*&#62;','','all');
&#60;/cfscript&#62;
&#60;cfdump var="#content#"&#62;</pre>
<p>Let&#8217;s take a look at the expression itself. The key portion is &#8216;[^&#62;]*&#8217;. The brackets are special characters that set apart that section of the expression. Inside the brackets we have ^&#62;. The ^ is a special character that means &#8216;not&#8217;. So the brackets tell us we&#8217;re looking for &#8216;not &#62;&#8217;. Next, we have the special character *, which means 0ne or more. Knowing this we can now read the entire expression to say &#8217;starts with &#60; then has 0ne or more characters that are not &#62; and ends with &#62;&#8217;.</p>
<p>In PHP the equivalent code would look like this:</p>
<pre>&#60;?php
$content = '&#60;div&#62;Tacos&#60;/div&#62;&#60;div&#62;Burritos&#60;/div&#62;&#60;div&#62;Tostadas&#60;/div&#62;';
$content = strip_tags($content);
echo $content;
?&#62;</pre>
<p><strong>Retrieving Content from an HTML Tag</strong></p>
<p>Instead of needing to remove tags, I have found myself needing to retrieve the content of a specific tag. In this example, we will look at retrieving the content of the title tag on a page.</p>
<p>First we&#8217;re going to look at a ColdFusion example:</p>
<pre>&#60;cfscript&#62;
str = "&#60;title&#62;Ricky Delicious Mexican Food&#60;/title&#62;";
arrTitle = REMatchNoCase('&#60;title&#62;.*(?=&#60;/title&#62;)',str);
if(NOT ArrayIsEmpty(arrTitle)) {
test = ReplaceNoCase(arrTitle[1], '&#60;title&#62;', '');
}
&#60;/cfscript&#62;
&#60;cfdump var="#test#"&#62;</pre>
<p>The first part of the expression says &#8220;Starts with &#60;title&#62;&#8221; and then we encounter the special character &#8216;.&#8217;. This will match any character except a newline &#8216;\n&#8217;. We then see the familiar * character. Which means we&#8217;re matching &#8216;any character except newline for zero or more times&#8217;. We then character a sequence in () which means these are &#8216;grouped&#8217;. Next we have a the character sequence &#8216;?=&#8217; which means this is a look ahead. A look ahead is a character sequence which we will end our match immediately before. So if we read this expression it says &#8220;Start with &#60;title&#62; then match any character but newlines on or more times and end immediately before &#60;title&#62;. Next we strip &#60;title&#62; from the returned string.</p>
<p>Now let&#8217;s take a look at this code in PHP:</p>
<pre>&#60;?php
$str = "&#60;title&#62;Ricky's Delicious Mexican Food";
if(preg_match( "/(?&#60;=&#60;title&#62;).*?(?=&#60;\/title&#62;)/i", $str, $matches)) {
$title = $matches[0];
}
echo $title;
?&#62;</pre>
<p>I&#8217;m using preg_match, which uses PERL syntax. The key thing to note about the differences in expressions is the availability of &#8216;look behinds&#8217; in PHP. A look behind is the exact opposite of a look ahead. It says &#8220;Start immediately after &#60;title&#62;&#8221;. This is why we can simply get the match and not have to strip the beginning tag. ColdFusion currently does not support look behinds, but I hope that in the future they add this functionality.</p>
<p><strong>Useful Tools:</strong></p>
<p><a href="http://www.regextester.com/" target="_blank">http://www.regextester.com/</a></p>
<p>I find this site very useful because it allows me to test my RegEx in real time. This saves me the time of making a change in the code and refreshing constantly.</p>
<p><a href="http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/" target="_blank">http://www.addedbytes.com/cheat-sheets/regular-expressions-cheat-sheet/</a></p>
<p>I&#8217;m a rather big fan of &#8216;cheat sheets&#8217;. It&#8217;s helpful to have one of these around whenever I find myself stuck.</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[PHP, fungsi trim(), htmlentities(), strip_tags()]]></title>
<link>http://syraru.wordpress.com/2008/10/18/php-fungsi-trim-htmlentities-strip_tags/</link>
<pubDate>Fri, 17 Oct 2008 17:01:21 +0000</pubDate>
<dc:creator>Red Dog</dc:creator>
<guid>http://syraru.wordpress.com/2008/10/18/php-fungsi-trim-htmlentities-strip_tags/</guid>
<description><![CDATA[Nah, berhubung awa masih ditugasin bikin website, awa ngejelasin tentang beberapa prosedur bwat ngej]]></description>
<content:encoded><![CDATA[Nah, berhubung awa masih ditugasin bikin website, awa ngejelasin tentang beberapa prosedur bwat ngej]]></content:encoded>
</item>
<item>
<title><![CDATA[checking the information from HTML forms]]></title>
<link>http://me2learn.wordpress.com/2008/10/01/checking-the-information-from-html-forms/</link>
<pubDate>Wed, 01 Oct 2008 18:57:43 +0000</pubDate>
<dc:creator>me2blog</dc:creator>
<guid>http://me2learn.wordpress.com/2008/10/01/checking-the-information-from-html-forms/</guid>
<description><![CDATA[b4 u use the values in your script, u need to check the variables to make sure they contain what u e]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>b4 u use the values in your script, u need to check the variables to make sure they contain what u expect &#8216;em to contain! Thus never trust info from user.</p>
<p><strong><span style="text-decoration:underline;">Checking for empty fields:</span></strong></p>
<p>u can require the user to enter info in a field and check when the user didn&#8217;t and let him back to re-fill that field using:</p>
<p><span style="color:#ff0000;">empty($_POST['<em>field_name</em>'])</span>;</p>
<p>this function returns true if the field is empty,,, false otherwise !</p>
<p><strong><span style="text-decoration:underline;">Checking for specific format:</span></strong></p>
<p>u can check using some built in functions like if u expect string, u can check using is_string and so on&#8230; for a table of these functions c this previous post <a title="Changing the order of statement execution" href="../2008/09/19/changing-the-order-of-statement-execution/">Changing the order of statement execution </a></p>
<p><strong><span style="text-decoration:underline;">Using regular expressions to check user input:</span></strong></p>
<p>u can aslo compare the info to a pattern to c if it matches if u care a lot about the information pattern using ereg function &#8230; for more in this ,,, check this previous post: <a title="pattern matching with regular expressions" href="../2008/09/19/pattern-matching-with-regular-expressions/">pattern matching with regular expressions</a></p>
<p><strong><span style="text-decoration:underline;">Cleaning information:</span></strong></p>
<ul>
<li>strip_tags: this function removes all tags from the text, u can keep some tags:</li>
</ul>
<p><span style="color:#ff0000;">$<em>variable_name</em> = strip_tags($_POST)['<em>field_name</em>'],&#8221;<em>&#60;tag u allow&#62; &#60;tag u allow&#62;</em>&#8220;);</span></p>
<ul>
<li>htmlspecialchars: this function changes some special characters to HTML into HTML format that allow &#8216;em to display without any special meaning</li>
</ul>
<p>Examples: &#60; become &#38;alt;</p>
<p>? become &#38;gt;</p>
<p>and &#38; become &#38;amp;</p>
<p><span style="color:#ff0000;">$<em>variable_nam</em>e= htmlspecialchars(</span><span style="color:#ff0000;">$_POST)['<em>field_name</em>']);</span></p>
<ul>
<li>trim: remove extra spaces at the beginning and the end of the field info, bcz it&#8217;s familiar that user enter spaces by mistake.</li>
</ul>
<p><span style="color:#ff0000;">$<em>variable_name</em>= trim(</span><span style="color:#ff0000;">$_POST)['<em>field_name</em>']);</span></p>
<p>Example:</p>
<p>in this example, i will use the same forms in the previous post but i will check for three fields (first name, second name and last name) not to keep blank ,,, if so &#8230; the user will be asked to re-fill &#8216;em &#8230;. if they r not blank , then it will output the same information in that example&#8230;.</p>
<p>Building the forms code:</p>
<p>&#60;br&#62;&#60;center&#62;&#60;h2&#62; Customer information &#60;/h2&#62;&#60;/center&#62;<br />
&#60;br&#62;&#60;br&#62;</p>
<p>&#60;center&#62;<br />
&#60;table border=&#8221;0&#8243;&#62;<br />
&#60;form action=&#8221;customer_info.php&#8221; method=&#8221;POST&#8221;&#62;<br />
&#60;tr&#62; &#60;td&#62; First name:&#60;/td&#62; &#60;td&#62; &#60;input type=&#8221;text&#8221; name=&#8221;first_name&#8221;&#62;&#60;/td&#62;&#60;/tr&#62;<br />
&#60;tr&#62; &#60;td&#62;Second name: &#60;/td&#62; &#60;td&#62; &#60;input type=&#8221;text&#8221; name=&#8221;second_name&#8221;&#62; &#60;/td&#62;&#60;/tr&#62;<br />
&#60;tr&#62;&#60;td&#62;Last name: &#60;/td&#62; &#60;td&#62; &#60;input type=&#8221;text&#8221; name=&#8221;last_name&#8221;&#62;&#60;/td&#62; &#60;/tr&#62;<br />
&#60;tr&#62;&#60;td&#62; Street Address:&#60;/td&#62;&#60;td&#62; &#60;input type=&#8221;text&#8221; name=&#8221;st_address&#8221;&#62;&#60;/td&#62; &#60;/tr&#62;<br />
&#60;tr&#62;&#60;td&#62; City:&#60;/td&#62;&#60;td&#62;<br />
&#60;select name=&#8221;city&#8221;<br />
&#60;option&#62; Amman &#60;/option&#62;<br />
&#60;option&#62; Aqaba &#60;/option&#62;<br />
&#60;option&#62; Irbd &#60;/option&#62;<br />
&#60;option&#62; Zarqa &#60;/option&#62;<br />
&#60;/td&#62; &#60;/tr&#62;<br />
&#60;tr&#62;&#60;td&#62;Sex: &#60;/td&#62;&#60;td&#62;<br />
&#60;input type =&#8221;radio&#8221; name=&#8221;Radio1&#8243; value= &#8220;M&#8221; &#62; Male<br />
&#60;input type =&#8221;radio&#8221; name=&#8221;Radio1&#8243; value= &#8220;F&#8221;&#62; Female<br />
&#60;/td&#62;&#60;/tr&#62;<br />
&#60;tr&#62;&#60;td&#62;Your Operating system: &#60;/td&#62;&#60;td&#62;<br />
&#60;input type= &#8220;checkbox&#8221; name=&#8221;os0&#8243; value=&#8221;W&#8221;&#62; Windows<br />
&#60;input type= &#8220;checkbox&#8221; name=&#8221;os1&#8243; value=&#8221;L&#8221;&#62; Linux<br />
&#60;input type= &#8220;checkbox&#8221; name=&#8221;os2&#8243; value=&#8221;M&#8221;&#62; Mac<br />
&#60;/td&#62;&#60;/tr&#62;<br />
&#60;/table&#62;&#60;br&#62;</p>
<p>&#60;input type=&#8221;submit&#8221; value=&#8221;submit name&#8221;&#62;<br />
&#60;/form&#62;</p>
<p><strong><em><span style="text-decoration:underline;">the customer info code:</span></em></strong></p>
<p>&#60;?php</p>
<p>function set_sex(){<br />
if ($_POST[Radio1]==&#8221;M&#8221;) {<br />
$sex= &#8220;Male&#8221;;<br />
}<br />
else<br />
{<br />
$sex= &#8220;Female&#8221;;}<br />
}</p>
<p>function print_info()<br />
{</p>
<p>echo &#8220;Welcome &#8220;,$_POST['first_name'],&#8221;!&#60;br&#62;&#8221;;<br />
echo &#8220;Your second name is: &#8220;,$_POST['second_name'];<br />
echo &#8220;&#60;br&#62;Your last name is: &#8220;,$_POST['last_name'];<br />
echo &#8220;&#60;br&#62;&#8221;;<br />
echo &#8220;you are &#8220;, $sex;<br />
echo &#8221; living in: &#8220;, $_POST[city];<br />
echo &#8220;  in the &#8220;, $_POST[st_address],&#8221; Street&#8221;;<br />
echo &#8220;&#60;br&#62;and your operating systems are: &#60;br&#62;&#8221;;</p>
<p>if (isset($_POST['os0'])) {<br />
echo &#8220;Windows&#60;br&#62;&#8221;;<br />
}</p>
<p>if (isset($_POST['os1'])) {<br />
echo &#8220;Linux&#60;br&#62;&#8221;;<br />
}</p>
<p>if (isset($_POST['os2'])) {<br />
echo &#8220;Mac&#60;br&#62;&#8221;;<br />
}<br />
return;<br />
}</p>
<p>function blank_check(){<br />
if (empty($_POST['first_name']))<br />
{<br />
echo &#8220;You didn&#8217;t enter your first name! &#60;br&#62;&#8221;;<br />
$blank_check_var = TRUE;<br />
}</p>
<p>if (empty($_POST['second_name']))<br />
{<br />
echo &#8220;You didn&#8217;t enter your second name! &#60;br&#62;&#8221;;<br />
$blank_check_var = TRUE;<br />
}</p>
<p>if (empty($_POST['last_name']))<br />
{<br />
echo &#8220;You didn&#8217;t enter your last name! &#60;br&#62;&#8221;;<br />
$blank_check_var = TRUE;<br />
}</p>
<p>return $blank_check_var;</p>
<p>}</p>
<p>//main<br />
set_sex();<br />
$check_var= blank_check();<br />
if (!$check_var){<br />
print_info();<br />
}</p>
<p>?&#62;</p>
<p>The output after leaving the first name blank is:</p>
<p>You didn&#8217;t enter your first name!</p>
<p>The output after leaving the first and second name blank is:</p>
<p>You didn&#8217;t enter your first name!<br />
You didn&#8217;t enter your second name!</p>
<p>The output after leaving the first, second and last name blank is:</p>
<p>You didn&#8217;t enter your first name!<br />
You didn&#8217;t enter your second name!<br />
You didn&#8217;t enter your last name!</p>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[C# source code for strip_tags in PHP]]></title>
<link>http://mustafaturan.wordpress.com/2008/09/04/csharp-source-code-for-strip_tags-in-php/</link>
<pubDate>Thu, 04 Sep 2008 23:52:08 +0000</pubDate>
<dc:creator>Mustafa Turan</dc:creator>
<guid>http://mustafaturan.wordpress.com/2008/09/04/csharp-source-code-for-strip_tags-in-php/</guid>
<description><![CDATA[Source to download: http://mustafaturan.net/download/lectures/csharp/strip_tags_csharp.txt // as a n]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><blockquote><p>Source to download: http://mustafaturan.net/download/lectures/csharp/strip_tags_csharp.txt</p>
<p>// as a namespace do not forget to add: using System.Text.RegularExpressions;<br />
static string strip_tags(string str, string allowed_tags)<br />
{<br />
/*<br />
// Coder: Mustafa Turan<br />
// Date: 05.09.2008<br />
// Contact:<br />
// http://mustafaturan.net/<br />
// http://mustafaturan.wordpress.com/<br />
// wm [ #at# ] mustafaturan.net<br />
// Licence: GNU and MIT Licence<br />
// EXAMPLES<br />
// &#8212;&#62;     function call1: strip_tags(&#8220;&#60;a href=\&#8221;asdadsadsad.html\&#8221;&#62;doctor&#60;/a&#62; &#60;p&#62;pirasa&#60;/p&#62; &#60;img src=\&#8221;asd.jpg\&#8221; /&#62; &#60;h1&#62;hey you&#60;/h1&#62;&#8221;, &#8220;&#60;a&#62;,&#60;p&#62;,&#60;img /&#62;&#8221;)<br />
// &#8212;&#62;     result: &#60;a href=&#8221;"&#62;doctor&#60;/a&#62; &#60;p&#62;pirasa&#60;/p&#62; &#60;img src=&#8221;asd.jpg&#8221; /&#62; hey you<br />
// &#8212;&#62;     function call2: strip_tags(&#8220;&#60;a href=\&#8221;asdadsadsad.html\&#8221;&#62;doctor&#60;/a&#62; &#60;p&#62;pirasa&#60;/p&#62; &#60;img src=\&#8221;asd.jpg\&#8221; /&#62; &#60;h1&#62;hey you&#60;/h1&#62;&#8221;, &#8220;&#8221;)<br />
// &#8212;&#62;     result: doctor pirasa hey you<br />
*/</p>
<p>// START<br />
// pattern for getting all tags<br />
string pattern_for_all_tags = &#8220;&#60;/?[^&#62;&#60;]+&#62;&#8221;;</p>
<p>// pattern for allowed tags<br />
string allowed_patterns = &#8220;&#8221;;<br />
if(allowed_tags!=&#8221;"){<br />
// get allowed tags if any exists<br />
Regex r = new Regex(&#8220;[\\/&#60;&#62; ]+&#8221;);<br />
allowed_tags = r.Replace(allowed_tags,&#8221;");<br />
string[] allowed_tags_array = allowed_tags.Split(&#8216;,&#8217;);<br />
foreach (string s in allowed_tags_array)<br />
{<br />
if (s == &#8220;&#8221;) continue;<br />
// Definin patterns<br />
string p_1 = &#8220;&#60;&#8221; + s + &#8221; [^&#62;&#60;]*&#62;$&#8221;;<br />
string p_2 = &#8220;&#60;&#8221; + s + &#8220;&#62;&#8221;;<br />
string p_3 = &#8220;&#60;/&#8221; + s + &#8220;&#62;&#8221;;<br />
if(allowed_patterns!=&#8221;")<br />
allowed_patterns += &#8220;&#124;&#8221;;<br />
allowed_patterns += p_1 + &#8220;&#124;&#8221; + p_2 + &#8220;&#124;&#8221; + p_3;<br />
}<br />
}</p>
<p>// Get all html tags included on string<br />
Regex strip_tags = new Regex(pattern_for_all_tags);<br />
MatchCollection all_tags_matched = strip_tags.Matches(str);</p>
<p>if (allowed_patterns != &#8220;&#8221;)<br />
foreach (Match m in all_tags_matched)<br />
{<br />
Regex r_1 = new Regex(allowed_patterns);<br />
Match m_1 = r_1.Match(m.Value);<br />
if (!m_1.Success)<br />
{<br />
// if not allowed replace it<br />
str = str.Replace(m.Value, &#8220;&#8221;);<br />
}<br />
}<br />
else<br />
// if not allow anyone replace all<br />
str = strip_tags.Replace(str, &#8220;&#8221;);<br />
return str;<br />
}</p></blockquote>
</div>]]></content:encoded>
</item>
<item>
<title><![CDATA[Strip_Tags() in ASP.NET]]></title>
<link>http://andreir.wordpress.com/2007/07/18/strip_tags-in-aspnet/</link>
<pubDate>Wed, 18 Jul 2007 21:05:24 +0000</pubDate>
<dc:creator>Andrei Rinea</dc:creator>
<guid>http://andreir.wordpress.com/2007/07/18/strip_tags-in-aspnet/</guid>
<description><![CDATA[Am scris un mic articolas cu o functie similara lui Strip_Tags() din PHP pe care bajetii de la ASP.N]]></description>
<content:encoded><![CDATA[<div class='snap_preview'><p>Am scris un mic articolas cu o functie similara lui Strip_Tags() din PHP pe care bajetii de la ASP.NET au cam ratat-o. Am scris metoda (&#8220;functia&#8221;) in C#. La testele de viteza a iesit destul de bine : cam 6 microsecunde pe un HTML de 25kb pe Intel Core Duo 1,83GHz si 1GB RAM.</p>
<p>Puteti vedea intregul articol (in engleza) pe CodeProject <a TITLE="echivalent Strip_Tags() in ASP.NET" HREF="http://www.codeproject.com/aspnet/htmlTagStripper.asp" TARGET="_blank">aici</a>.</p>
</div>]]></content:encoded>
</item>

</channel>
</rss>
