<?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>Blog.hio.fr &#187; highlight</title>
	<atom:link href="http://blog.hio.fr/tag/highlight/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hio.fr</link>
	<description></description>
	<lastBuildDate>Tue, 07 Sep 2010 04:42:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>PHP Highlight</title>
		<link>http://blog.hio.fr/2009/03/04/php-highlight/</link>
		<comments>http://blog.hio.fr/2009/03/04/php-highlight/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 08:07:44 +0000</pubDate>
		<dc:creator>HiO</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[highlight]]></category>

		<guid isPermaLink="false">http://blog.hio.fr/?p=106</guid>
		<description><![CDATA[Surligner des mot dans un texte en php]]></description>
			<content:encoded><![CDATA[<p>Surligner des mot dans un texte en php</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> highLight<span style="color: #009900;">&#40;</span><span style="color: #000088;">$words</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$highlight</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;strong&gt;$0&lt;/strong&gt;'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$pattern</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'#(?!&amp;lt;.*?)(%s)(?![^&amp;lt;&amp;gt;]*?&amp;gt;)#i'</span><span style="color: #339933;">;</span>
    <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>
        <span style="color: #000088;">$word</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_quote</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$word</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$regex</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$pattern</span><span style="color: #339933;">,</span> <span style="color: #000088;">$word</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$regex</span><span style="color: #339933;">,</span> <span style="color: #000088;">$highlight</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Utilisation:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$words_to_hl</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'clovis'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'franc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> highLight<span style="color: #009900;">&#40;</span><span style="color: #000088;">$words_to_hl</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Tu m\'etonnes que Clovis a eclate tt le monde en son temps, les anciens Francs etaient 655 fois plus nombreux.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ce qui nous donne:</p>
<p><em>Tu m&#8217;etonnes que <strong>Clovis</strong> a eclate tt le monde en son temps, les anciens <strong>Franc</strong>s etaient 655 fois plus nombreux.</em></p>
<p>Voir ce bout de code en action sur <a href="http://quote-de-porc.com/quotes/search?p=1&amp;what=humour">quote de porc</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.hio.fr/2009/03/04/php-highlight/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
