<?xml version="1.0" encoding="UTF-8"?>
<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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>simra &#187; Code Snippets</title>
	<atom:link href="http://www.simra.ch/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.simra.ch</link>
	<description>development &#38; design</description>
	<lastBuildDate>Fri, 26 Mar 2010 15:57:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Highlight Search Words in php</title>
		<link>http://www.simra.ch/2010/02/highlight-search-words-in-php/</link>
		<comments>http://www.simra.ch/2010/02/highlight-search-words-in-php/#comments</comments>
		<pubDate>Sat, 06 Feb 2010 17:30:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[eregi_replace]]></category>
		<category><![CDATA[ereg_replace]]></category>
		<category><![CDATA[preg_replace]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[RegularExpressions]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=1102</guid>
		<description><![CDATA[Many sites have opted for highlighting the keywords from their searches. This can be useful for quickly finding relavant words within large pages of text. 
The following php function highlights words within html content (words in tags  are ignored). Here you can find a live demo http://www.newsaddict.ch.

function highlight_html_content &#40;$text, $search&#41;
&#123;
&#160; &#160; $search = eregi_replace&#40;&#34;[^-a-zA-Z0-9üäöÜÄÖèéê&#38;']&#34;, [...]]]></description>
			<content:encoded><![CDATA[<p>Many sites have opted for highlighting the keywords from their searches. This can be useful for quickly finding relavant words within large pages of text. </p>
<p>The following php function highlights words within html content (words in tags <> are ignored). Here you can find a live demo <a href="http://www.newsaddict.ch" target="_blank">http://www.newsaddict.ch</a>.<br />
<span id="more-1102"></span></p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">function</span> highlight_html_content <span style="color: #009900;">&#40;</span><span style="color: #000088;">$text</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$search</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/eregi_replace"><span style="color: #990000;">eregi_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[^-a-zA-Z0-9üäöÜÄÖèéê&amp;']&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Sonderzeichen entfernen </span><br />
&nbsp; &nbsp; <span style="color: #000088;">$search</span><span style="color: #339933;">=</span> <a href="http://www.php.net/ereg_replace"><span style="color: #990000;">ereg_replace</span></a> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;[ ]+&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Doppelte Leerzeichen entfernen</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$words</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$search</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Array mit Wörter erstellen</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$word</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$w</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_quote"><span style="color: #990000;">preg_quote</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$word</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$regexp</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/(<span style="color: #006699; font-weight: bold;">$w</span>)(?![^&lt;]+&gt;)/iu&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Wörter innerhalb eines Tags werden ignoriert -&gt; i Gross-/Kleinschreibung nicht beachten -&gt; u UTF8 damit ä=Ä ü=Ü...</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$replacement</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;b style=&quot;color:#FF0&quot;&gt;\\1&lt;/b&gt;'</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$text</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/preg_replace"><span style="color: #990000;">preg_replace</span></a> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$regexp</span><span style="color: #339933;">,</span><span style="color: #000088;">$replacement</span> <span style="color: #339933;">,</span><span style="color: #000088;">$text</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$text</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2010/02/highlight-search-words-in-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Getting the Screen Size in Java</title>
		<link>http://www.simra.ch/2010/01/getting-the-screen-size-in-java/</link>
		<comments>http://www.simra.ch/2010/01/getting-the-screen-size-in-java/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 20:35:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[GraphicsEnvironment]]></category>
		<category><![CDATA[toolkit]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=1058</guid>
		<description><![CDATA[Here&#8217;s a little exmple on how to get the screen size of one or multiple monitors in Java.

Get the size of the default screen:
Dimension dim = Toolkit.getDefaultToolkit&#40;&#41;.getScreenSize&#40;&#41;;
If more than one screen is available, this example gets the size of each screen:
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment&#40;&#41;;
GraphicsDevice&#91;&#93; gs = ge.getScreenDevices&#40;&#41;;

// Get size of each screen
for &#40;int i=0; i&#60;gs.length; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little exmple on how to get the screen size of one or multiple monitors in Java.<br />
<span id="more-1058"></span><br />
Get the size of the default screen:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Adimension+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Dimension</span></a> dim <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Atoolkit+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Toolkit</span></a>.<span style="color: #006633;">getDefaultToolkit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getScreenSize</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>If more than one screen is available, this example gets the size of each screen:</p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agraphicsenvironment+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">GraphicsEnvironment</span></a> ge <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agraphicsenvironment+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">GraphicsEnvironment</span></a>.<span style="color: #006633;">getLocalGraphicsEnvironment</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Agraphicsdevice+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">GraphicsDevice</span></a><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> gs <span style="color: #339933;">=</span> ge.<span style="color: #006633;">getScreenDevices</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Get size of each screen</span><br />
<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&lt;</span>gs.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; DisplayMode dm <span style="color: #339933;">=</span> gs<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">getDisplayMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> screenWidth <span style="color: #339933;">=</span> dm.<span style="color: #006633;">getWidth</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">int</span> screenHeight <span style="color: #339933;">=</span> dm.<span style="color: #006633;">getHeight</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2010/01/getting-the-screen-size-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modulo 11 Prüfziffer in FoxPro</title>
		<link>http://www.simra.ch/2009/12/modulo-11-prufziffer-in-foxpro/</link>
		<comments>http://www.simra.ch/2009/12/modulo-11-prufziffer-in-foxpro/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 13:12:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[FoxPro]]></category>
		<category><![CDATA[Algorithmus]]></category>
		<category><![CDATA[Modulo 11]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=1036</guid>
		<description><![CDATA[Hier eine kleine FoxPro Funktion zum Berechnen der «Modulo 11» Prüffziffer.

PROCEDURE modulo_11 &#40;s&#41;
&#160; &#160; LOCAL x,z,t, c,r,y
&#160; &#160; t=0
&#160; &#160; c=7
&#160; &#160; FOR x = LEN&#40;s&#41; TO 1 STEP -1
&#160; &#160; &#160; &#160; z = VAL&#40;SUBSTR&#40;s,x,1&#41;&#41;
&#160; &#160; &#160; &#160; t = t + c*z
&#160; &#160; &#160; &#160; c=c-1
&#160; &#160; &#160; &#160; IF c&#60;2
&#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Hier eine kleine FoxPro Funktion zum Berechnen der «Modulo 11» Prüffziffer.<br />
<span id="more-1036"></span></p>
<div class="codecolorer-container visualfoxpro default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="visualfoxpro codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: blue;">PROCEDURE</span> modulo_11 <span style="color: blue;">&#40;</span>s<span style="color: blue;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: blue;">LOCAL</span> x<span style="color: blue;">,</span>z<span style="color: blue;">,</span><span style="color: blue;">t</span><span style="color: blue;">,</span> c<span style="color: blue;">,</span>r<span style="color: blue;">,</span><span style="color: blue;">y</span><br />
&nbsp; &nbsp; <span style="color: blue;">t</span><span style="color: blue;">=</span>0<br />
&nbsp; &nbsp; c<span style="color: blue;">=</span>7<br />
&nbsp; &nbsp; <span style="color: blue;">FOR</span> x <span style="color: blue;">=</span> <span style="color: blue;">LEN</span><span style="color: blue;">&#40;</span>s<span style="color: blue;">&#41;</span> <span style="color: blue;">TO</span> 1 <span style="color: blue;">STEP</span> <span style="color: blue;">-</span>1<br />
&nbsp; &nbsp; &nbsp; &nbsp; z <span style="color: blue;">=</span> <span style="color: blue;">VAL</span><span style="color: blue;">&#40;</span><span style="color: blue;">SUBSTR</span><span style="color: blue;">&#40;</span>s<span style="color: blue;">,</span>x<span style="color: blue;">,</span>1<span style="color: blue;">&#41;</span><span style="color: blue;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">t</span> <span style="color: blue;">=</span> <span style="color: blue;">t</span> <span style="color: blue;">+</span> c<span style="color: blue;">*</span>z<br />
&nbsp; &nbsp; &nbsp; &nbsp; c<span style="color: blue;">=</span>c<span style="color: blue;">-</span>1<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">IF</span> c<span style="color: blue;">&lt;</span>2<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; c<span style="color: blue;">=</span>7<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">ENDIF</span><br />
&nbsp; &nbsp; <span style="color: blue;">ENDFOR</span><br />
&nbsp; &nbsp; r <span style="color: blue;">=</span> <span style="color: blue;">int</span><span style="color: blue;">&#40;</span><span style="color: blue;">t</span><span style="color: blue;">/</span>11<span style="color: blue;">&#41;</span><br />
&nbsp; &nbsp; r <span style="color: blue;">=</span> t<span style="color: blue;">-</span><span style="color: blue;">&#40;</span>r<span style="color: blue;">*</span>11<span style="color: blue;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: blue;">IF</span> r<span style="color: blue;">&lt;=</span>9<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">y</span><span style="color: blue;">=</span><span style="color: #ff0000;">&quot;0&quot;</span><span style="color: blue;">+</span><span style="color: blue;">ALLTRIM</span><span style="color: blue;">&#40;</span><span style="color: blue;">STR</span><span style="color: blue;">&#40;</span>r<span style="color: blue;">&#41;</span><span style="color: blue;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: blue;">ELSE</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">y</span><span style="color: blue;">=</span><span style="color: blue;">ALLTRIM</span><span style="color: blue;">&#40;</span><span style="color: blue;">STR</span><span style="color: blue;">&#40;</span>r<span style="color: blue;">&#41;</span><span style="color: blue;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: blue;">ENDIF</span><br />
&nbsp; &nbsp; <span style="color: blue;">RETURN</span> <span style="color: blue;">y</span><br />
<span style="color: blue;">ENDIF</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2009/12/modulo-11-prufziffer-in-foxpro/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>handle mouse click events in Java</title>
		<link>http://www.simra.ch/2009/12/handle-mouse-click-event-in-java/</link>
		<comments>http://www.simra.ch/2009/12/handle-mouse-click-event-in-java/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 10:07:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[MouseAdapter]]></category>
		<category><![CDATA[mouseClicked]]></category>
		<category><![CDATA[mouseEntered]]></category>
		<category><![CDATA[MouseEvent]]></category>
		<category><![CDATA[mouseExited]]></category>
		<category><![CDATA[mousePressed]]></category>
		<category><![CDATA[mouseReleased]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=1026</guid>
		<description><![CDATA[Here&#8217;s a little example on how to add a mouseListener to the component via addMouseListener.

&#160; &#160; &#160; table.addMouseListener&#40;new MouseAdapter&#40;&#41; &#123;
&#160; &#160; &#160; &#160; &#160; &#160; @Override
&#160; &#160; &#160; &#160; &#160; &#160; public void mouseClicked&#40;MouseEvent e&#41; &#123;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if &#40;e.getButton&#40;&#41; == MouseEvent.NOBUTTON&#41; &#123;
&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a little example on how to add a mouseListener to the component via addMouseListener.<br />
<span id="more-1026"></span></p>
<div class="codecolorer-container java default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="java codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp; table.<span style="color: #006633;">addMouseListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseadapter+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseAdapter</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> mouseClicked<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getButton</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a>.<span style="color: #006633;">NOBUTTON</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No button clicked...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getButton</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a>.<span style="color: #006633;">BUTTON1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Button 1 clicked...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getButton</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a>.<span style="color: #006633;">BUTTON2</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Button 2 clicked...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getButton</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a>.<span style="color: #006633;">BUTTON3</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Button 3 clicked...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Number of click: &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getClickCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Click position (X, Y): &nbsp;&quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getX</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;, &quot;</span> <span style="color: #339933;">+</span> e.<span style="color: #006633;">getY</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> mouseEntered<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> mouseExited<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> mousePressed<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @Override<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> mouseReleased<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Amouseevent+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">MouseEvent</span></a> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2009/12/handle-mouse-click-event-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get all domains in the Active Directory using C#</title>
		<link>http://www.simra.ch/2009/12/how-to-get-list-of-domains-in-active-directory-in-c/</link>
		<comments>http://www.simra.ch/2009/12/how-to-get-list-of-domains-in-active-directory-in-c/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 10:01:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippets]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=1008</guid>
		<description><![CDATA[The following C# function returns a list of all domains in the Active Directory using System.DirectoryServices.

private StringCollection GetDomains&#40;&#41;
&#123;
&#160; &#160; StringCollection domains= new StringCollection&#40;&#41;;
&#160; &#160; try
&#160; &#160; &#123;
&#160; &#160; &#160; &#160; DirectorySearcher ds= new DirectorySearcher&#40;&#34;objectCategory=Domain&#34;&#41;;
&#160; &#160; &#160; &#160; SearchResultCollection src= ds.FindAll&#40;&#41;;
&#160; &#160; &#160; &#160; foreach &#40;SearchResult rs in src&#41;
&#160; &#160; &#160; &#160; &#123;
&#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>The following C# function returns a list of all domains in the Active Directory using System.DirectoryServices.<br />
<span id="more-1008"></span></p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF;">private</span> StringCollection GetDomains<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; StringCollection domains<span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StringCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">try</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; DirectorySearcher ds<span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> DirectorySearcher<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;objectCategory=Domain&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; SearchResultCollection src<span style="color: #008000;">=</span> ds.<span style="color: #0000FF;">FindAll</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>SearchResult rs <span style="color: #0600FF;">in</span> src<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ResultPropertyCollection rpc<span style="color: #008000;">=</span> rs.<span style="color: #0000FF;">Properties</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span> <span style="color: #FF0000;">object</span> d <span style="color: #0600FF;">in</span> rpc<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;name&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; domains.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>d.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0600FF;">return</span> domains<span style="color: #008000;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2009/12/how-to-get-list-of-domains-in-active-directory-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regular Expressions in C#</title>
		<link>http://www.simra.ch/2009/12/regular-expression-in-c/</link>
		<comments>http://www.simra.ch/2009/12/regular-expression-in-c/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 19:48:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[innerhtml]]></category>
		<category><![CDATA[nested tags]]></category>
		<category><![CDATA[Regex]]></category>
		<category><![CDATA[RegularExpressions]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=967</guid>
		<description><![CDATA[A regular expression is a pattern of text that describes what to match in a string. It serves as a filter to find what you&#8217;re looking for. The two main function of using regular expression is to match and to replace. The former determines if the pattern is in the string, and if so, find [...]]]></description>
			<content:encoded><![CDATA[<p>A regular expression is a pattern of text that describes what to match in a string. It serves as a filter to find what you&#8217;re looking for. The two main function of using regular expression is to match and to replace. The former determines if the pattern is in the string, and if so, find it. Replace changes the string according to the pattern to another pattern.<br />
<span id="more-967"></span></p>
<blockquote><p>You can use regular expression (Regex) in your C# (or any other .NET language) application by importing the namespace System.Text.RegularExpressions. </p></blockquote>
<p>The following examples show the usage of Regular Expressions in C#. I needed them in one of my project to find stuff on a website and I find them very useful. </p>
<p>Returns the innerHtml of a tag (i.e. div) with certain attributes (works with nested tags):</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">String</span> GetInnerHtml<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> content, <span style="color: #FF0000;">String</span> tag, <span style="color: #FF0000;">String</span> attr<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; Regex re <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Regex<span style="color: #000000;">&#40;</span><span style="color: #666666;">@&quot;(&lt;&quot;</span> <span style="color: #008000;">+</span> tag <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">+</span> attr <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;(.*?)&gt;).*?((?&lt;TAG&gt;&lt;&quot;</span> <span style="color: #008000;">+</span> tag <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;).*?(?&lt;-TAG&gt;&lt;/&quot;</span> <span style="color: #008000;">+</span> tag <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&gt;))?(?(TAG)(?!))&lt;/&quot;</span> <span style="color: #008000;">+</span> tag <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #0600FF;">return</span> re.<span style="color: #0000FF;">Match</span><span style="color: #000000;">&#40;</span>content<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Returns all Email-Addresses:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">String</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> GetEmailAddresses<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> content<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; Regex re <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Regex<span style="color: #000000;">&#40;</span><span style="color: #666666;">@&quot;[\w\.-]{1,}@[\w\.-]{2,}\.\w{2,3}&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; MatchCollection emails <span style="color: #008000;">=</span> re.<span style="color: #0000FF;">Matches</span><span style="color: #000000;">&#40;</span>content<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #FF0000;">String</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> s <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span>emails.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> x <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> x <span style="color: #008000;">&lt;</span> emails.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span> x<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; s<span style="color: #000000;">&#91;</span>x<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> emails<span style="color: #000000;">&#91;</span>x<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #0600FF;">return</span> s<span style="color: #008000;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Removes all tags:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">String</span> RemoveTags<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> content<span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; Regex re <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Regex<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;(&lt;[^&gt;]*&gt;)&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; content <span style="color: #008000;">=</span> re.<span style="color: #0000FF;">Replace</span><span style="color: #000000;">&#40;</span>content, <span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #0600FF;">return</span> content<span style="color: #008000;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Returns the title tag:</p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">String</span> GetTitle<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> content<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; Regex re <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Regex<span style="color: #000000;">&#40;</span><span style="color: #666666;">@&quot;(?&lt;=&lt;title.*&gt;)([\s\S]*)(?=&lt;/title&gt;)&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #0600FF;">return</span> re.<span style="color: #0000FF;">Match</span><span style="color: #000000;">&#40;</span>content<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2009/12/regular-expression-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get the content of an url in C#</title>
		<link>http://www.simra.ch/2009/12/get-the-content-of-url-c/</link>
		<comments>http://www.simra.ch/2009/12/get-the-content-of-url-c/#comments</comments>
		<pubDate>Tue, 08 Dec 2009 21:26:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[HttpWebRequest]]></category>
		<category><![CDATA[url content]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=962</guid>
		<description><![CDATA[This is a easy way to get the content of a url into a string. You only need to open a new connection using HttpWebRequest, make a request and read the stream into a string. see the example below:

using System;
using System.Net;
using System.IO;

class functions
&#123;
&#160; public static String GetUrlContent&#40;String Url&#41;
&#160; &#123;
&#160; &#160; &#160; // Open a connection
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>This is a easy way to get the content of a url into a string. You only need to open a new connection using HttpWebRequest, make a request and read the stream into a string. see the example below:<br />
<span id="more-962"></span></p>
<div class="codecolorer-container csharp default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Net</span><span style="color: #008000;">;</span><br />
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #FF0000;">class</span> functions<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">String</span> GetUrlContent<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> Url<span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Open a connection</span><br />
&nbsp; &nbsp; &nbsp; HttpWebRequest hwr <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>HttpWebRequest<span style="color: #000000;">&#41;</span>HttpWebRequest.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span>Url<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Specify header information like </span><br />
&nbsp; &nbsp; &nbsp; hwr.<span style="color: #0000FF;">UserAgent</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;simra.ch GetUrlContent&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; hwr.<span style="color: #0000FF;">Referer</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;http://www.simra.ch/&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Get the Request</span><br />
&nbsp; &nbsp; &nbsp; WebResponse wr <span style="color: #008000;">=</span> hwr.<span style="color: #0000FF;">GetResponse</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Open a new Stream</span><br />
&nbsp; &nbsp; &nbsp; Stream ws <span style="color: #008000;">=</span> wr.<span style="color: #0000FF;">GetResponseStream</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Create a SteamReader</span><br />
&nbsp; &nbsp; &nbsp; StreamReader sr <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StreamReader<span style="color: #000000;">&#40;</span>ws<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Read the stream</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">String</span> content <span style="color: #008000;">=</span> sr.<span style="color: #0000FF;">ReadToEnd</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-style: italic;">// Cleanup</span><br />
&nbsp; &nbsp; &nbsp; sr.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; ws.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; wr.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">return</span> content<span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2009/12/get-the-content-of-url-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Youtube Video Downloader in PHP</title>
		<link>http://www.simra.ch/2009/12/youtube-video-downloader-in-php/</link>
		<comments>http://www.simra.ch/2009/12/youtube-video-downloader-in-php/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 12:35:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[get_video]]></category>
		<category><![CDATA[video_id]]></category>
		<category><![CDATA[youtube]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=885</guid>
		<description><![CDATA[The following Php-Script is able to download videos from youtube in three different formats (MP4 for hight, FLV for medium and 3GP for low quality). In addition the script provides a preview of the current video.

View Demo

Here&#8217;s the source:
&#60;?php
if&#40;isset&#40;$_GET&#91;'u'&#93;&#41;&#41;&#123;
&#160; &#160; $v = urldecode&#40;$_GET&#91;'u'&#93;&#41;;
&#160; &#160; if&#40;$_GET&#91;'fmt'&#93; == 17&#41;&#123; // 3gp
&#160; &#160; &#160; &#160; header&#40;&#34;Content-Type: video/3gp&#34;&#41;; &#160;
&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>The following Php-Script is able to download videos from youtube in three different formats (MP4 for hight, FLV for medium and 3GP for low quality). In addition the script provides a preview of the current video.</p>
<p><a href="http://onyou.ch/services/?service=youtube_downloader.php" target="_blank"><br />
View Demo</a></p>
<p><span id="more-885"></span><br />
Here&#8217;s the source:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;height:300px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'u'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$v</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/urldecode"><span style="color: #990000;">urldecode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'u'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fmt'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">17</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// 3gp</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: video/3gp&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: attachment; filename=<span style="color: #000099; font-weight: bold;">\&quot;</span>video.3gp<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$v</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;&amp;amp;fmt=17&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'fmt'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">18</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// mp4</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: video/mp4&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: attachment; filename=<span style="color: #000099; font-weight: bold;">\&quot;</span>video.mp4<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$v</span><span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;&amp;amp;fmt=18&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// flv</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Type: video/x-flv&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Content-Disposition: attachment; filename=<span style="color: #000099; font-weight: bold;">\&quot;</span>video.flv<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> &nbsp;<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/readfile"><span style="color: #990000;">readfile</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$v</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/flush"><span style="color: #990000;">flush</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <a href="http://www.php.net/exit"><span style="color: #990000;">exit</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$yu</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://www.youtube.com/watch?v=qGyfaoUAWtM'</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/isset"><span style="color: #990000;">isset</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;yu&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$yu</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;yu&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$yu</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&quot;video_id&quot;: &quot;(.*?)&quot;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #339933;">,</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <a href="http://www.php.net/preg_match"><span style="color: #990000;">preg_match</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&quot;t&quot;: &quot;(.*?)&quot;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #339933;">,</span> <span style="color: #000088;">$m1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$m</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$t</span> &nbsp;<span style="color: #339933;">=</span> <span style="color: #000088;">$m1</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$u</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.youtube.com/get_video?video_id=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&amp;t=&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$t</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<br />
&lt;h1&gt;Youtube Url:&lt;/h1&gt;<br />
&lt;form method=&quot;get&quot; id=&quot;form&quot; onSubmit=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<br />
&lt;input type=&quot;text&quot; name=&quot;yu&quot; id=&quot;yu&quot; size=&quot;80&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$yu</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;/&gt; &lt;input type=&quot;submit&quot; name=&quot;b&quot; id=&quot;b&quot; value=&quot;Load&quot; /&gt;<br />
&lt;/form&gt;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
&lt;h1&gt;Prewiew:&lt;/h1&gt;<br />
&lt;img src=&quot;http://img.youtube.com/vi/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$id</span><span style="color: #000000; font-weight: bold;">?&gt;</span>/1.jpg&quot; alt=&quot;Preview 1&quot; /&gt;<br />
&lt;img src=&quot;http://img.youtube.com/vi/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$id</span><span style="color: #000000; font-weight: bold;">?&gt;</span>/2.jpg&quot; alt=&quot;Preview 2&quot; /&gt;<br />
&lt;img src=&quot;http://img.youtube.com/vi/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$id</span><span style="color: #000000; font-weight: bold;">?&gt;</span>/3.jpg&quot; alt=&quot;Preview 3&quot; /&gt;<br />
<br />
&lt;h1&gt;Downloads:&lt;/h1&gt;<br />
&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?u='</span><span style="color: #339933;">.</span><a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$u</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Download FLV&lt;/a&gt;&lt;br /&gt;<br />
&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?fmt=18&amp;u='</span><span style="color: #339933;">.</span><a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$u</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Download MP4&lt;/a&gt;&lt;br /&gt;<br />
&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'PHP_SELF'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?fmt=17&amp;u='</span><span style="color: #339933;">.</span><a href="http://www.php.net/urlencode"><span style="color: #990000;">urlencode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$u</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;Download 3GP&lt;/a&gt;<br />
<br />
<span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>Please check out my <a href="http://www.simra.ch/2009/12/youtube-video-downloader-in-python/">Youtube Video Downloader in Python</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2009/12/youtube-video-downloader-in-php/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>wxPython File Save Dialog</title>
		<link>http://www.simra.ch/2009/12/wxpython-file-save-dialog/</link>
		<comments>http://www.simra.ch/2009/12/wxpython-file-save-dialog/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 09:11:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[wxFileDialog]]></category>
		<category><![CDATA[wxPython]]></category>

		<guid isPermaLink="false">http://www.simra.ch/?p=881</guid>
		<description><![CDATA[This is an example on how to use the wxFileDialog. It allows the user to save or open a file. Setting up a basic dialog is pretty simple.

from wxPython.wx import *

app = wx.PySimpleApp&#40;&#41;
saveDlg= wxFileDialog &#40; None, style = wxOPEN &#41;

if saveDlg.ShowModal&#40;&#41; == wxID_OK:
&#160; &#160; print 'Selected:', saveDlg.GetPath&#40;&#41;

saveDlg.Destroy&#40;&#41;
]]></description>
			<content:encoded><![CDATA[<p>This is an example on how to use the wxFileDialog. It allows the user to save or open a file. Setting up a basic dialog is pretty simple.<br />
<span id="more-881"></span></p>
<div class="codecolorer-container python default" style="overflow:auto;white-space:nowrap;border: 1px solid #9F9F9F;width:435px;"><div class="python codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #ff7700;font-weight:bold;">from</span> wxPython.<span style="color: black;">wx</span> <span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #66cc66;">*</span><br />
<br />
app = wx.<span style="color: black;">PySimpleApp</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
saveDlg= wxFileDialog <span style="color: black;">&#40;</span> <span style="color: #008000;">None</span>, style = wxOPEN <span style="color: black;">&#41;</span><br />
<br />
<span style="color: #ff7700;font-weight:bold;">if</span> saveDlg.<span style="color: black;">ShowModal</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> == wxID_OK:<br />
&nbsp; &nbsp; <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">'Selected:'</span>, saveDlg.<span style="color: black;">GetPath</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><br />
<br />
saveDlg.<span style="color: black;">Destroy</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.simra.ch/2009/12/wxpython-file-save-dialog/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

