<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- generator="wordpress/2.0.3" -->
<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>Mikael Brevik</title>
	<link>http://mikaelb.net</link>
	<description>PHP, MySQL, CSS, XHTML, JavaScript</description>
	<pubDate>Tue, 26 Aug 2008 13:09:38 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.3</generator>
	<language>en</language>
			<item>
		<title>ALA: The Survey 2008</title>
		<link>http://mikaelb.net/2008/ala-the-survey-2008/</link>
		<comments>http://mikaelb.net/2008/ala-the-survey-2008/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 06:45:25 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Webutvikling</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/ala-the-survey-2008/</guid>
		<description><![CDATA[
Da var det den tiden av året igjen. A List Apart har kommet med dette årets utgave av den ganske nye årlige spørreundersøkelsen for oss som jobber som utviklere/designere og lignende på web. Jeg har tatt testen, og det burde du gjøre og. Alltid like spennende å se hvordan resultatet blir for ditt område/land osv.
Det [...]]]></description>
			<content:encoded><![CDATA[<p><a class="left" title="The Web Design Survey, 2008" href="http://www.alistapart.com/articles/survey2008"><img src="http://aneventapart.com/webdesignsurvey/templates/ala/images/i-took-the-2008-survey.gif" /></a><br />
Da var det den tiden av året igjen. A List Apart har kommet med dette årets utgave av den ganske nye årlige spørreundersøkelsen for oss som jobber som utviklere/designere og lignende på web. Jeg har tatt testen, og det burde du gjøre og. Alltid like spennende å se hvordan resultatet blir for ditt område/land osv.</p>
<p>Det tar ikke lang tid å gjennomføre testen. 18 sider av enkle spørsmål som går i alt fra arbeidsforhold, inntekter og til kompetanseområde. Testen er anonym, så det er ingen grunn til å ikke ta den.</p>
<p>Hvorfor ta testen? Målet er å kartlegge markedet vi jobber i.
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/ala-the-survey-2008/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Manglende bakoverkompabilitet i WordPress?</title>
		<link>http://mikaelb.net/2008/manglende-bakoverkompabilitet-i-wordpress/</link>
		<comments>http://mikaelb.net/2008/manglende-bakoverkompabilitet-i-wordpress/#comments</comments>
		<pubDate>Wed, 30 Apr 2008 02:13:40 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Tanker</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/manglende-bakoverkompabilitet-i-wordpress/</guid>
		<description><![CDATA[Skriver denne posten litt i frustrasjon. Er det manglende bakoverkompabilitet i WP? Det kan virke slik. Jeg kjører 2.0.3 på denne bloggen (kall meg gjerne lat), og har problemer med enkelt å overføre postene mine til en nyinstallasjon av WP 2.5. 
Det ser ut som om jeg må gjøre dette manuelt, noe som innebærer unødvendig [...]]]></description>
			<content:encoded><![CDATA[<p>Skriver denne posten litt i frustrasjon. Er det manglende bakoverkompabilitet i <acronym title="WordPress">WP</acronym>? Det kan virke slik. Jeg kjører 2.0.3 på denne bloggen (kall meg gjerne lat), og har problemer med enkelt å overføre postene mine til en nyinstallasjon av <acronym title="WordPress">WP</acronym> 2.5. </p>
<p>Det ser ut som om jeg må gjøre dette manuelt, noe som innebærer unødvendig mye stress.<br />
Jeg får se på det når jeg har tid og krefter&#8230;
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/manglende-bakoverkompabilitet-i-wordpress/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Bestilt meg ny MacBook Pro</title>
		<link>http://mikaelb.net/2008/bestilt-meg-ny-mac-book-pro/</link>
		<comments>http://mikaelb.net/2008/bestilt-meg-ny-mac-book-pro/#comments</comments>
		<pubDate>Fri, 18 Apr 2008 07:42:33 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Blogg</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/bestilt-meg-ny-mac-book-pro/</guid>
		<description><![CDATA[
Da har jeg endelig gått til innkjøp av ny Mac. Det er på tide med ny maskin, da min gamle iBook begynner å dra på åra. Maskinen ble som følger:

2.4GHz Intel Core 2 Duo
MacBook Pro 15-inch Widescreen
2GB 667 DDR2 SDRAM - 2&#215;1GB
250GB Serial ATA @ 5400 rpm
SuperDrive 8x DL
Apple Remote
No iWork Preinstalled
No Final Cut Exp [...]]]></description>
			<content:encoded><![CDATA[<p><img id="image170" src="http://mikaelb.net/wp-content/uploads/2008/04/Bilde 2.png" alt="MBP Bestilling" /></p>
<p>Da har jeg endelig gått til innkjøp av ny Mac. Det er på tide med ny maskin, da min gamle iBook begynner å dra på åra. Maskinen ble som følger:</p>
<ul>
<li>2.4GHz Intel Core 2 Duo</li>
<li>MacBook Pro 15-inch Widescreen</li>
<li>2GB 667 DDR2 SDRAM - 2&#215;1GB</li>
<li>250GB Serial ATA @ 5400 rpm</li>
<li>SuperDrive 8x DL</li>
<li>Apple Remote</li>
<li>No iWork Preinstalled</li>
<li>No Final Cut Exp Preinstalled</li>
<li>No Aperture Preinstalled</li>
<li>No Logic Exp Preinstalled</li>
<li>BkLit Keyboard/Mac <acronym title="Operating System">OS</acronym>-H</li>
<li>Country Kit-NOB</li>
</ul>
<p>I tillegg ble det innkjøp av ekstra minne, så det blir oppgradert til 4 <acronym title="Gigabyte">GB</acronym>. Håper den lever opp til forventningene, og jeg må si jeg gleder meg som en unge.</p>
<p><img id="image171" src="http://mikaelb.net/wp-content/uploads/2008/04/Bilde 3.png" alt="Apple MacBook Pro" />
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/bestilt-meg-ny-mac-book-pro/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Ny mulighet for oss CSS-nudister</title>
		<link>http://mikaelb.net/2008/ny-mulighet-for-oss-css-nudister/</link>
		<comments>http://mikaelb.net/2008/ny-mulighet-for-oss-css-nudister/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 10:59:10 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Blogg</category>
	<category>Webutvikling</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/ny-mulighet-for-oss-css-nudister/</guid>
		<description><![CDATA[Som i fjor har året i år en egen dag for oss som liker å kle oss naken. For å være konkret så er det for oss som liker å kle nettstedet vårt naken. For min del var fjoråret en stor suksess med mange trackbacks og god respons. Jeg håper året i år vil føre [...]]]></description>
			<content:encoded><![CDATA[<p>Som i fjor har året i år en egen dag for oss som liker å kle oss naken. For å være konkret så er det for oss som liker å kle <em>nettstedet</em> vårt naken. For min del var fjoråret en stor suksess med mange trackbacks og god respons. Jeg håper året i år vil føre med seg enda større deltagelse og omtalen i rundt det blir enda større enn det noen gang har vært. </p>
<p>I år er dagen 4 dager senere, men det er ingen hindring. Arrangør-nettstedet er det samme som tidligere (<a href="http://naked.dustindiaz.com/">naked.dustindiaz.com</a>), så meld dere på før dere glemmer. Gjør også klar eventuelle koder, plugins eller verktøy om dere ikke er sikre på at dere husker å gjøre det manuelt når dagen er kommet. Husk å ta høyde for tidsforskjeller rundt om i verden. </p>
<p>Så håper jeg at <a href="http://mikaelb.net/2007/la-oss-bli-nakne/">alle som var med i fjor</a> vil være med i år. Jeg vet i alle fall at Bza er trofast og kommer til å kle seg <a href="http://bza.no/naken-og-fri/">naken og fri</a>.</p>
<p>Liste over norske deltakelser <small>(oppdateres etterhvert)</small></p>
<ul>
<li><a href="http://bza.no">Bza</a></li>
<li><a href="http://www.hellandberger.org/">Einars blogg</a>
</li>
<li><a href="http://audun.norblogg.net/">Auduns IT weblogg</a></li>
<li><a href="http://blumonkey.org/">BluMonkey</a></li>
<li><a href="http://www.auduns.no/">Audun Sæther</a></li>
</ul>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/ny-mulighet-for-oss-css-nudister/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Wordpress 2.5 er nesten klar</title>
		<link>http://mikaelb.net/2008/wordpress-25-er-nesten-klar/</link>
		<comments>http://mikaelb.net/2008/wordpress-25-er-nesten-klar/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 09:38:25 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Blogg</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/wordpress-25-er-nesten-klar/</guid>
		<description><![CDATA[Som de fleste vet, kjører jeg Wordpress på denne bloggen. Wordpress er et verktøy jeg har lært å elske med tiden. Både dens mulighet til å lage template/mal på en ganske grei måte, men også muligheten jeg får til å endre funksjonalliteten og skrive egne plugins. Man har store muligheter til å egendefinere hvordan bloggen [...]]]></description>
			<content:encoded><![CDATA[<p>Som de fleste vet, kjører jeg Wordpress på denne bloggen. Wordpress er et verktøy jeg har lært å elske med tiden. Både dens mulighet til å lage template/mal på en ganske grei måte, men også muligheten jeg får til å endre funksjonalliteten og skrive egne plugins. Man har store muligheter til å egendefinere hvordan bloggen skal fungere. </p>
<p>Nå for 8 dager siden kom Wordpress med en stor lansering (RC 1) som ser ut til å være en av de større oppdateringene Wordpress har kommet med på lang tid. Versjonene håpper fra 2.3.3 til 2.5. Det er helt ny UI på kontrollpanelet, og flere muligheter når det kommer til funksjonallitet. </p>
<p>For å nevne noen oppdateringer:</p>
<ul>
<li><acronym title="WordPress">WP</acronym> kommer nå med støtte for Gravatar &#8220;ut av boksen&#8221;.</li>
<li><acronym title="Really Simple Syndication">RSS</acronym>-strøm med full tekst</li>
<li>&#8220;Medfødt&#8221; støtte for tags</li>
<li>Enklere oppdatering av plugins</li>
</ul>
<p>Les alt om oppdateringene på <a href="http://wordpress.org/development/2008/03/25-sneak-peek/">Wordpress&#8217; egne sider</a>, og fortell meg hva dere syns.</p>
<p>Jeg kommer til å kjøre RC-1 på en lokal server for testing. Så får vi se når det er klart for oppdatering på denne siden. Wordpress selv mener 2.5 er stabil og er klar for full lansering, men vil være på den sikre siden å vente til flere tilbakemeldinger er inne.</p>
<p>Men en ting skal være sikkert, skjermskuddene fra det nye kontrollpanelet ser herlig ut.
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/wordpress-25-er-nesten-klar/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Tall datatyper i MySQL</title>
		<link>http://mikaelb.net/2008/tall-datatyper-i-mysql/</link>
		<comments>http://mikaelb.net/2008/tall-datatyper-i-mysql/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 09:28:38 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>PHP / MySQL</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/tall-datatyper-i-mysql/</guid>
		<description><![CDATA[I dag har jeg tenkt å gå litt på det banale, men som jeg ser mange er usikre på. Det er rett og slett kopiert direkte fra manualen til MySQL, men det er ikke sikkert alle som finner den eller er klare over det.
For enkelte er det kanskje ikke greit å vite hvilken INT-type man [...]]]></description>
			<content:encoded><![CDATA[<p>I dag har jeg tenkt å gå litt på det banale, men som jeg ser mange er usikre på. Det er rett og slett kopiert direkte fra manualen til MySQL, men det er ikke sikkert alle som finner den eller er klare over det.</p>
<p>For enkelte er det kanskje ikke greit å vite hvilken INT-type man skal ha til tider. Er det <code>TINYINT</code> jeg vil ha? Eler er det kanskje <code>SMALLINT</code>? Hvor går grensen, hvor store verdier? </p>
<p>I manuelen finner vi denne tabellen, som er en temmelig grei oversikt over hvor store verdier du kan ha på de forskjellige INT-typene</p>
<blockquote>
<table>
<tbody>
<tr>
<td><span class="bold"><strong>Type</strong></span></td>
<td><span class="bold"><strong>Bytes</strong></span></td>
<td><span class="bold"><strong>Minimum Value</strong></span></td>
<td><span class="bold"><strong>Maximum Value</strong></span></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><span class="bold"><strong>(Signed/Unsigned)</strong></span></td>
<td><span class="bold"><strong>(Signed/Unsigned)</strong></span></td>
</tr>
<tr>
<td><code class="literal">TINYINT</code></td>
<td>1</td>
<td><code class="literal">-128</code></td>
<td><code class="literal">127</code></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><code class="literal">0</code></td>
<td><code class="literal">255</code></td>
</tr>
<tr>
<td><code class="literal">SMALLINT</code></td>
<td>2</td>
<td><code class="literal">-32768</code></td>
<td><code class="literal">32767</code></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><code class="literal">0</code></td>
<td><code class="literal">65535</code></td>
</tr>
<tr>
<td><code class="literal">MEDIUMINT</code></td>
<td>3</td>
<td><code class="literal">-8388608</code></td>
<td><code class="literal">8388607</code></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><code class="literal">0</code></td>
<td><code class="literal">16777215</code></td>
</tr>
<tr>
<td><code class="literal">INT</code></td>
<td>4</td>
<td><code class="literal">-2147483648</code></td>
<td><code class="literal">2147483647</code></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><code class="literal">0</code></td>
<td><code class="literal">4294967295</code></td>
</tr>
<tr>
<td><code class="literal">BIGINT</code></td>
<td>8</td>
<td><code class="literal">-9223372036854775808</code></td>
<td><code class="literal">9223372036854775807</code></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><code class="literal">0</code></td>
<td><code class="literal">18446744073709551615</code></td>
</tr>
</tbody>
</table>
</blockquote>
<p>Dette gir en pekepinne på hvilken type man skal bruke på de forskjellige feltene når du lager en tabell. Det er ikke alt for mye optimalisering å hente på å sette feltene til lavest mulig, men som man sier: «Mange bekker små, gjør en stor å».
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/tall-datatyper-i-mysql/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Sektor: 790 Personlig næringsdrivende</title>
		<link>http://mikaelb.net/2008/sektor-790-personlig-naeringsdrivende/</link>
		<comments>http://mikaelb.net/2008/sektor-790-personlig-naeringsdrivende/#comments</comments>
		<pubDate>Wed, 26 Mar 2008 09:07:48 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Blogg</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/sektor-790-personlig-naeringsdrivende/</guid>
		<description><![CDATA[
Jeg har for litt siden bestemt meg for å satse mer seriøst som frilanser i webutvikling og andre relaterte tjenester, og derfor startet prosessen om å starte nytt firma og ansette regnskapsfører.
Jeg startet med dette for vell 3 uker siden, og nå begynner det å ta form. Bedriften min har nå endret navn til Brevik [...]]]></description>
			<content:encoded><![CDATA[<p><img id="image166" src="http://mikaelb.net/wp-content/uploads/2008/03/Bilde 1.png" alt="Brreg info Brevik Web" /></p>
<p>Jeg har for litt siden bestemt meg for å satse mer seriøst som frilanser i webutvikling og andre relaterte tjenester, og derfor startet prosessen om å starte nytt firma og ansette regnskapsfører.</p>
<p>Jeg startet med dette for vell 3 uker siden, og nå begynner det å ta form. Bedriften min har nå endret navn til Brevik Web og alt begynner å falle på plass. </p>
<p>Jeg vil gratulere meg selv med nytt firma, og ønske meg lykke til.
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/sektor-790-personlig-naeringsdrivende/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Oppstarterguiden for frilansere</title>
		<link>http://mikaelb.net/2008/oppstarterguiden-for-frilansere/</link>
		<comments>http://mikaelb.net/2008/oppstarterguiden-for-frilansere/#comments</comments>
		<pubDate>Sun, 23 Mar 2008 02:23:54 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Webutvikling</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/oppstarterguiden-for-frilansere/</guid>
		<description><![CDATA[
Screenshot av Frilansinfo.no, av Atle Hansson
Det er sikkert ikke bare meg her som jobber som frilanser i webutvikling. For at man skulle kunne dra noen penger inn på dette, må man selvsagt være registrert som et foretak. Dette gjør at man kan sende ut fakturaer, og drive respektabelt. Men det er ikke alltid like enkelt [...]]]></description>
			<content:encoded><![CDATA[<p><img id="image165" src="http://mikaelb.net/wp-content/uploads/2008/03/Bilde 4.png" alt="Frilansinfo.no av Atle Hansson" /><br />
<small><em>Screenshot av Frilansinfo.no, av Atle Hansson</em></small></p>
<p>Det er sikkert ikke bare meg her som jobber som frilanser i webutvikling. For at man skulle kunne dra noen penger inn på dette, må man selvsagt være registrert som et foretak. Dette gjør at man kan sende ut fakturaer, og drive respektabelt. Men det er ikke alltid like enkelt å vite hvor man skal starte, og hva man skal gjøre når man har funnet ut hvordan. <a href="http://www.frilansinfo.no/" title="Frilansinfo.no">Frilansinfo.no</a> har i løpet av en kortere periode publisert 6 artikler som tar deg fra A til Å når du skal registrere foretak, og den første perioden deretter. Hadde jeg bare sett denne for noen år siden, hadde det spart meg mye tid å krefter i egen research. Guidene finner du under <a href="http://www.frilansinfo.no/category/etablere/oppstart">Etablere->Oppstartsguide</a>. </p>
<p>Det hele starter med forberedelsene. Er du klar til å starte gründer-tilværelsen? Etter første artikkel i serien, går de videre til grunner til å bli frilanser, navnvelgelse på foretaket, selvskapsformer og registrering av foretaket. Til slutt kommer den delen jeg likte best; «<a href="http://www.frilansinfo.no/startguiden-del-6-10-ting-aa-gjore-de-forste-ukene-som-selvstendig-naeringsdrivende">Startguiden [6]: 10 ting å gjøre de første ukene som selvstendig næringsdrivende</a>». Her er det veldig mye bra lesestoff å hente. </p>
<p>Lesestoffet begrenser seg ikke bare til oppstartsguiden, men sprer seg også utover hele siden. Her kan du blant annet hente ut maler på kontrakter, fakturaer, m.m.. All kudos til <a href="http://www.illustrasjon.net/">Atle Hansson</a> for å ha nok initativ til å starte siden.
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/oppstarterguiden-for-frilansere/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>TinyMCE med en gratis og brukbar bildebehandler</title>
		<link>http://mikaelb.net/2008/tinymce-med-en-gratis-og-brukbar-bildebehandler/</link>
		<comments>http://mikaelb.net/2008/tinymce-med-en-gratis-og-brukbar-bildebehandler/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 23:10:49 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Webutvikling</category>
	<category>JavaScript</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/tinymce-med-en-gratis-og-brukbar-bildebehandler/</guid>
		<description><![CDATA[Alle av oss som har brukt TinyMCE vet at det er vanskelig å finne en god bildebehandler som også er gratis. Du har altids TinyMCEs eget alternativ, men det koster $47 kun for en-siders lisens. Greit nok, de skal tjene penger og TinyMCE er gratis. Du kan ikke alltid få i poser og sekk. 
Alle [...]]]></description>
			<content:encoded><![CDATA[<p>Alle av oss som har brukt TinyMCE vet at det er vanskelig å finne en god bildebehandler som også er gratis. Du har altids TinyMCEs eget alternativ, men det koster $47 kun for en-siders lisens. Greit nok, de skal tjene penger og TinyMCE er gratis. Du kan ikke alltid få i poser og sekk. </p>
<p>Alle de forskjellige bildebehandlerne jeg har prøvd per dags dato har vært fulle av feil og mangler. Dette så jeg meg lei på i dag, og bestemte meg for å få den nyeste versjonen av <strong><a href="http://sourceforge.net/tracker/index.php?func=detail&#038;aid=1776979&#038;group_id=103281&#038;atid=738747">ImageManager</a></strong> til å fungere. Siden jeg ikke fikk den til å fungere slik som den var. </p>
<p>Her kommer det en komplett guide til hvordan du får den til å fungere.</p>
<ol>
<li><a href="http://sourceforge.net/tracker/download.php?group_id=103281&#038;atid=738747&#038;file_id=243906&#038;aid=1776979">Last ned ImageManager</a>.</li>
<li>Kopier filene over til strukturen din, den passer godt i samme mappe som du har tiny_mce js-filene. Jeg har den i en mappe ovenfor root</li>
<li>Legg til følgende under <code>tinyMCE.init</code><br />
<div class="syntax_hilite">
<div id="javascript-5">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">plugins : <span style="color: #3366CC;">"advimage"</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">file_browser_callback : <span style="color: #3366CC;">"fileBrowserCallBack"</span>, </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</li>
<li>Så Legger du til ImageManagers settinger under settingen av TinyMCE:<br />
<div class="syntax_hilite">
<div id="html-6">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #CCCCCC; font-style: italic;">&lt;!-- start of calls --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #009933;">&lt;script</span></a> <span style="color: #009933;">type</span>=<span style="color: #0066FF;">"text/javascript"</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009933;">src</span>=<span style="color: #0066FF;">"js/ImageManager/assets/dialog.js"</span><span style="color: #009933;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #009933;">&lt;/script&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #009933;">&lt;script</span></a> <span style="color: #009933;">type</span>=<span style="color: #0066FF;">"text/javascript"</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009933;">src</span>=<span style="color: #0066FF;">"js/ImageManager/IMEStandalone.js"</span><span style="color: #009933;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #009933;">&lt;/script&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #009933;">&lt;script</span></a> <span style="color: #009933;">language</span>=<span style="color: #0066FF;">"javascript"</span> <span style="color: #009933;">type</span>=<span style="color: #0066FF;">"text/javascript"</span><span style="color: #009933;">&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;var connector = &quot;../../../ImageManager/manager.php&quot;;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;// dynamic path to images dir</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;base = &quot;../../image_uploads/&quot;;&nbsp; &nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;// relative url to images dir</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;path = &quot;/image_uploads/&quot;;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;//Create a new Imanager Manager, needs </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;// the directory and which language translation to use.</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;var manager = new ImageManager('js/ImageManager','en');&nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #009933;">&lt;/script&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/script.html"><span style="color: #009933;">&lt;script</span></a> <span style="color: #009933;">language</span>=<span style="color: #0066FF;">"javascript"</span> <span style="color: #009933;">type</span>=<span style="color: #0066FF;">"text/javascript"</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009933;">src</span>=<span style="color: #0066FF;">"js/ImageManager/tinycall.js"</span><span style="color: #009933;">&gt;</span></a></span><span style="color: #009900;"><span style="color: #009933;">&lt;/script&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #CCCCCC; font-style: italic;">&lt;!-- end of calls --&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<ul>
<li><code>connector</code> skal være i forhold til <strong>'tiny_mce/plugins/advimage'</strong>, så har du det i samme mappe-plassering som meg blir det korrekt med 3 * ../</li>
<li><code>base</code> skal være i forhold til en <acronym title="Pre-Hypertext Processing">PHP</acronym>-fil som du finner i ImageManager-mappen. En gang tilbake (../) blir altså på mappen der du har tiny_mce og ImageManager, en gang til tilbake og du kommer til root, om du har det som meg.</li>
<li><code>path</code> er til bildepath. Den er i forhold til root. Du må prøve litt ut på disse mappe-stiene for å se hva som passer deg.</li>
</ul>
</li>
<li>Her kommer feilen med ImageManager som tok meg en evighet å finne ut av. Gå inn på filen <code>tinycall.js</code> som følger med ImageManager. Der, på linje 8, endrer du<br />
<div class="syntax_hilite">
<div id="javascript-7">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">src_field</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
til </p>
<div class="syntax_hilite">
<div id="javascript-8">
<div class="javascript">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #66cc66;">&#40;</span>src_field<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
</li>
</ol>
<p>Da skal du være ferdig, og alt fungerer slik det skal. Du finner ImageManager ved en knapp til høyre for Image Path i den vanlige Image-plugin som følger med TinyMCE.<br />
<img id="image159" src="http://mikaelb.net/wp-content/uploads/2008/02/Bilde 7.png" alt="ImageManager button" /></p>
<p>ImageManager ser nå, for meg, slik ut:<br />
<img id="image161" src="http://mikaelb.net/wp-content/uploads/2008/02/imagemanager.png" alt="ImageManager preview" />
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/tinymce-med-en-gratis-og-brukbar-bildebehandler/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Nye elementer med HTML5</title>
		<link>http://mikaelb.net/2008/nye-elementer-med-html5/</link>
		<comments>http://mikaelb.net/2008/nye-elementer-med-html5/#comments</comments>
		<pubDate>Sat, 26 Jan 2008 20:27:57 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>CSS / (X)HTML</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/nye-elementer-med-html5/</guid>
		<description><![CDATA[Som mange vet er HTML5 nå lansert. Med dette er det mange nye elementer som har kommet, og mange endringer som har gjort. Noe av de mest spesielle endringene, syns jeg, er den nye måten å bruke DOCTYPE på. Tidligere var HTML basert på SGML og derfor måtte du referere til en DTD. Dette er [...]]]></description>
			<content:encoded><![CDATA[<p>Som mange vet er HTML5 nå lansert. Med dette er det mange nye elementer som har kommet, og mange endringer som har gjort. Noe av de mest spesielle endringene, syns jeg, er den nye måten å bruke DOCTYPE på. Tidligere var <acronym title="HyperText Markup Language">HTML</acronym> basert på <acronym title="Standard General Markup Language">SGML</acronym> og derfor måtte du referere til en <acronym title="Document Type Definition">DTD</acronym>. Dette er nå ikke nødvendig og derfor holder det med en enkel</p>
<div class="syntax_hilite">
<div id="html-10">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #00bbdd;">&lt;!DOCTYPE html&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Andre geniale endringer er nye elementer som har kommet. Dette er noen av mine favoritter:</p>
<ul>
<li><code>header</code> » Markerer headeren på siden din</li>
<li><code>footer</code> » Markerer footeren på siden din</li>
<li><code>nav</code> » Markerer navigasjonen på siden din</li>
<li><code>article</code> » Markerer en artikkel på siden din, f.eks nyhet eller blogginnlegg.</li>
<li><code>dialog</code> » Sier seg selv, en dialog mellom to personer.</li>
</ul>
<p>I tillegg har vi også de ganske omtalte <code>audio-</code> og <code>video</code>-elementene som er for media på siden din, og gjør det enklere å vise filmer eller musikk på siden din. </p>
<p>I tillegg til dette er det veldig store forbedringer i <a href="http://www.w3.org/TR/web-forms-2/">FORM-håndtering og laging i HTML5</a>.</p>
<p>For mer lesing om HTML5 kan dere se på <a href="http://www.w3.org/TR/2008/WD-html5-diff-20080122/">forskjellene mellom HTML4 og HTML5</a> eller lese <a href="http://www.w3.org/TR/html5/">spesifikasjonene til <acronym title="HyperText Markup Language">HTML</acronym> 5</a>.
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/nye-elementer-med-html5/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Norsk Webforum med phpBB3</title>
		<link>http://mikaelb.net/2008/norsk-webforum-med-phpbb3/</link>
		<comments>http://mikaelb.net/2008/norsk-webforum-med-phpbb3/#comments</comments>
		<pubDate>Sat, 19 Jan 2008 15:23:53 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Blogg</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/norsk-webforum-med-phpbb3/</guid>
		<description><![CDATA[
I går midt på dagen skjedde det. Norsk Webforum (NWF) oppgraderte fra phpBB2 til phpBB3. Til nå har det vært positive tilbakemeldinger, og jeg er også fornøyd med at ledelsen valgte å gjøre det. Det har blitt testet grundig på forhånd, så det ble ikke noen merkbare feil ved konverteringen.
Foreløpig kjøres forumet med default design, [...]]]></description>
			<content:encoded><![CDATA[<p><img id="image155" src="http://mikaelb.net/wp-content/uploads/2008/01/nwf_changed.gif" alt="Norsk Webforum forumbytte" /></p>
<p>I går midt på dagen skjedde det. <a href="http://norskwebforum.no">Norsk Webforum (<acronym title="Norsk WebForum">NWF</acronym>)</a> oppgraderte fra phpBB2 til phpBB3. Til nå har det vært positive tilbakemeldinger, og jeg er også fornøyd med at ledelsen valgte å gjøre det. Det har blitt testet grundig på forhånd, så det ble ikke noen merkbare feil ved konverteringen.</p>
<p>Foreløpig kjøres forumet med default design, til og med uten <a href="http://norskwebforum.no"><acronym title="Norsk WebForum">NWF</acronym></a> logo, men det skal det forhåpentligvis bli en endring på. <a href="http://norskwebforum.no"><acronym title="Norsk WebForum">NWF</acronym></a> har etterlyst en designer som er villig til å lage et nytt design til siden, da de mener det er på tide med et helt bytt av profil på <acronym title="Norsk WebForum">NWF</acronym>. Det har nå vært 5 år med samme programvaren, samme designet og samme logoen. Jeg kan derfor si meg enig med administrator jobela (aka Lurifax) om at det nå er på tide å tre inn i 2008 med ny og freshere stil. </p>
<p>Jeg håper derfor på at en begavet designer sier seg villig til å lage et design til <a href="http://norskwebforum.no"><acronym title="Norsk WebForum">NWF</acronym></a>, og at det blir en fantastisk rengjøring og oppgradering fra tidligere design fra Compute og PepperX. </p>
<p>Det er mulig jeg kommer til å savne "gamle" <a href="http://norskwebforum.no"><acronym title="Norsk WebForum">NWF</acronym></a>, for som de sier er det dumt å endre på perfeksjon. Men la oss håpe det er verdt det denne gangen. </p>
<p>Hva syns du om <a href="http://norskwebforum.no">NWFs</a> forumbytte?
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/norsk-webforum-med-phpbb3/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>En god debugging funksjon til live debugging.</title>
		<link>http://mikaelb.net/2008/en-god-debugging-funksjon-til-live-debugging/</link>
		<comments>http://mikaelb.net/2008/en-god-debugging-funksjon-til-live-debugging/#comments</comments>
		<pubDate>Mon, 14 Jan 2008 08:05:48 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>PHP / MySQL</category>
		<guid isPermaLink="false">http://mikaelb.net/2008/en-god-debugging-funksjon-til-live-debugging/</guid>
		<description><![CDATA[Denne posten er inspirert av en post på siden dev1.no, med navn Feilsøking i webapplikasjoner som er i drift.
Når en skal debugge bruker vi som regel en enkel





&#60;?php


&#160; &#160;die&#40;'Her'&#41;;


?&#62; 






Eller lignende for å indikere hvor det stopper i scriptet. Om du debugger en side som er live, vil du gjerne ikke stoppe hele siden for [...]]]></description>
			<content:encoded><![CDATA[<p><small>Denne posten er inspirert av en post på siden <a href="http://dev1.no">dev1.no</a>, med navn <a href="http://dev1.no/artikkel/50/feilsking-i-webapplikasjoner-som-er-i-drift#comment-9" title="Nyhet: Feilsøking i webapplikasjoner som er i drift">Feilsøking i webapplikasjoner som er i drift</a>.</small></p>
<p>Når en skal debugge bruker vi som regel en enkel</p>
<div class="syntax_hilite">
<div id="php-17">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://www.php.net/die"><span style="color:#0000FF;">die</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'Her'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Eller lignende for å indikere hvor det stopper i scriptet. Om du debugger en side som er live, vil du gjerne ikke stoppe hele siden for alle brukere. Derfor vil du gjerne kun vise debugging infoen for deg, og ingen andre. Det er flere måter å gjøre det på, men måten jeg ville ha brukt er funksjonen nedenfor. </p>
<p>Først og fremst må du opprette en variabel/array som inkluderes til alle sider. Dette skal ikke være et problem om du har en config-fil eller funksjoner som du inkluderer og er nødvendig for systemet. Da er det bare å sette opp følgende en plass hvor hele systemet får tak i det:</p>
<div class="syntax_hilite">
<div id="php-18">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: red;">$debug_info</span> = <a href="http://www.php.net/array"><span style="color:#0000FF;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Ikke bare må det settes, men også en funksjon som gjør at det blir enklere å legge til informasjonen i arrayen. Du kan selvfølgelig gjøre det manuelt, men det kan bli litt tungvindt etterhvert. Så vi har en wrapper funksjon som gjør det meste for deg:</p>
<div class="syntax_hilite">
<div id="php-19">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/function"><span style="color:#0000FF;">function</span></a> debug <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$line</span>, <span style="color: red;">$file</span>, <span style="color: red;">$message</span>, &amp;<span style="color: red;">$debug_info</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$statement</span> = <span style="color:#006600;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#03B903;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$statement</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: red;">$debug_info</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC0000;">'Line: '</span> . <span style="color: red;">$line</span> . <span style="color:#CC0000;">'. File: '</span> . <span style="color: red;">$file</span> . </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#CC0000;">'. Message: '</span> . <span style="color: red;">$message</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#03B903;">return</span> <span style="color:#006600;">true</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#03B903;">return</span> <span style="color:#006600;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Her bruker vi noe som kalles call-by-referance. Det vil si at du kan gjøre endringer på variablen satt i argumentet og det vil også skje endringer på variablen du setter i argumentet. </p>
<p>Måten du finner linje og fil på er enkelt med __line__ og __file__. Dette blir satt i argumenter for å finne hvor det er du kjører funksjonen, og ikke der du oppretter funksjonen. </p>
<p>$statement er noe du setter til å bli i boolean-verdi. Dette kan være f.eks brukersjekk. Som du kan se eksempel på under her. </p>
<p>Når du kaller funksjonen kan det ca se slik ut:</p>
<div class="syntax_hilite">
<div id="php-20">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;debug <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600;">__line__</span>, <span style="color:#006600;">__file__</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">'Feiler med MySQL-spørring. Query: '</span> . <span style="color: red;">$query</span>, <span style="color: red;">$debug_info</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$_SESSION</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#CC0000;">'userid'</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color: red;">$admin_userid</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Eller om du ikke har noen kriterier til if-statementet.</p>
<div class="syntax_hilite">
<div id="php-21">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;debug <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600;">__line__</span>, <span style="color:#006600;">__file__</span>, <span style="color:#CC0000;">'Feiler ved punkt 3.'</span>, <span style="color: red;">$debug_info</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Slik får du informasjon om hvilken fil det er, hvilken linje det skjer på og hva feilen er. Og når du vil skrive ut feilmeldingene kan du enten lage en egen side som inkluderer filen hvor funksjonen og variablen blir satt, eller du kan skrive ut $debug_info nederst på indeks-siden.</p>
<div class="syntax_hilite">
<div id="php-22">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/print_r"><span style="color:#0000FF;">print_r</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$debug_info</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Slik er det du kan debugge en side live, uten at besøkende ser det som skjer.
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2008/en-god-debugging-funksjon-til-live-debugging/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Godt nytt år til alle lesere</title>
		<link>http://mikaelb.net/2007/godt-nytt-ar-til-alle-lesere/</link>
		<comments>http://mikaelb.net/2007/godt-nytt-ar-til-alle-lesere/#comments</comments>
		<pubDate>Mon, 31 Dec 2007 20:26:39 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Blogg</category>
		<guid isPermaLink="false">http://mikaelb.net/2007/godt-nytt-ar-til-alle-lesere/</guid>
		<description><![CDATA[Jeg er klar over at etter jeg kom inn i militæret, og det var over én måneds tørke på bloggen min, gikk det kraftig nedover i leserantall på bloggen. Til tross av dette så må jeg si meg fornøyd med året 2007. Det har vært toppåret for min del, når det gjelder blogging og antall [...]]]></description>
			<content:encoded><![CDATA[<p>Jeg er klar over at etter jeg kom inn i militæret, og det var over én måneds tørke på bloggen min, gikk det kraftig nedover i leserantall på bloggen. Til tross av dette så må jeg si meg fornøyd med året 2007. Det har vært toppåret for min del, når det gjelder blogging og antall lesere. Dette er basert på respons jeg har fått, antall lenker jeg har funnet inn til bloggen min og ikke minst statistikken jeg har sett i kontrollpanelet mitt. Siden bloggen har vært såpass inaktiv i det siste vil det bli en ekstra utfordring å få bloggen tilbake til at jeg får noen kommentarer på hver post. </p>
<p>Det varmer en bloggers hjerte når en får respons via kommentarer. Selv om det er kritikk, så lenge det er konstruktivt og noe man kan lære av og bygge videre på. Derfor håper jeg for det nye året på masse ny lærdom og en propersjonal økning i lesere. Masse ny lærdom håper jeg for alle, og ikke bare for meg selv.</p>
<p>Hva det nye året bringer, kan aldri si for sikkert. Selv skal jeg prøve (og sannsynligvis sikkert lykkes) med å få en suksess her i militæret, i en form av å ha det veldig morsomt og lærerikt, og ikke minst starte på skole over sommeren. Det skal bli spennende, da jeg ikke vet hva det bringer. Nye situasjoner og nye muligheter for å lære er noe alle burde ta i mot med åpne armer. Problemstillinger som du møter på manges normalt sett lineære liv, er bare noe du kan bygge på å bli sterkere av.</p>
<p>Med dette ønsker jeg alle dere et riktig godt nytt år, og glem ikke å se på bloggen min med gjevne mellomrom. Tilbring denne dagen med kjente og kjære. Glem for all del ikke å nyte det muligens siste året med skikkelig fyrverkerier. Selv får jeg prøve å nyte dagen, selv om jeg er i militæret fremfor med mine kjære.
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2007/godt-nytt-ar-til-alle-lesere/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>MySQL: PHPs natsort () i MySQL</title>
		<link>http://mikaelb.net/2007/mysql-phps-natsort-i-mysql/</link>
		<comments>http://mikaelb.net/2007/mysql-phps-natsort-i-mysql/#comments</comments>
		<pubDate>Mon, 31 Dec 2007 13:05:48 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>PHP / MySQL</category>
		<guid isPermaLink="false">http://mikaelb.net/2007/mysql-phps-natsort-i-mysql/</guid>
		<description><![CDATA[Opp til flere ganger har folk spørt meg om jeg har en løsning på naturlig sortering på tall i MySQL-tabeller. Dette er egentlig et problem som er veldig enkelt å unngå. Det skal lite til, og har du det slik det burde være så er det ikke et problem i det heletatt. 
Problemet er at [...]]]></description>
			<content:encoded><![CDATA[<p>Opp til flere ganger har folk spørt meg om jeg har en løsning på naturlig sortering på tall i MySQL-tabeller. Dette er egentlig et problem som er veldig enkelt å unngå. Det skal lite til, og har du det slik det <strong>burde</strong> være så er det ikke et problem i det heletatt. </p>
<p>Problemet er at det blir en ikke naturlig sortering på tall, og det blir problemer med at 10 kommer før 2 osv. Først om hvordan man kunne ha ungått problemet, og så om hvordan man kan løse det når det er oppstått.</p>
<h3>Bedre føre var...</h3>
<p>Nevnte problem skjer om du har fieldtype som VARCHAR eller annen tekst-type. Om du har feltet som en INTEGER ville ikke dette være noe problem i det heletatt, og det hadde blitt sortert etter verdi slik som faller mennesket naturlig. </p>
<h3>Når skaden først har skjedd</h3>
<p>Når skaden først har skjedd er det to ting du kan gjøre. Du kan enten kjøre en ALTER på feltet og gjøre det om til INTEGER, eller du kan kjøre MySQLs CAST()-funksjon i spørringen. Måten dette gjøres på er som følger:</p>
<div class="syntax_hilite">
<div id="mysql-24">
<div class="mysql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SELECT</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;numbers </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">FROM</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;table </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">ORDER</span> <span style="color: #993333; font-weight: bold;">BY</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;CAST <span style="color: #66cc66;">&#40;</span>numbers AS <span style="color: #aa3399; font-weight: bold;">UNSIGNED</span> <span style="color: #aa9933; font-weight: bold;">INTEGER</span><span style="color: #66cc66;">&#41;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">-- [ DESC / ASC ] </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Da burde biffen være løst. Lykke til med sorteringen.
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2007/mysql-phps-natsort-i-mysql/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Bzas webordbok på norsk</title>
		<link>http://mikaelb.net/2007/bzas-webordbok-pa-norsk/</link>
		<comments>http://mikaelb.net/2007/bzas-webordbok-pa-norsk/#comments</comments>
		<pubDate>Mon, 31 Dec 2007 06:43:18 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Webutvikling</category>
		<guid isPermaLink="false">http://mikaelb.net/2007/bzas-webordbok-pa-norsk/</guid>
		<description><![CDATA[Bza skrev i går et veldig bra prosjekt som går ut på å starte en webordbok om faglige uttrykk i webutvikling på norsk. Dette syns jeg er en glimrende idé da det per dags dato mangler mange passende og fult dekkende ord i substitutt for de engelske som vi alle bruker til daglig. 
Derfor anbefaler [...]]]></description>
			<content:encoded><![CDATA[<p>Bza skrev i går et veldig bra prosjekt som går ut på å starte en webordbok om faglige uttrykk i webutvikling på norsk. Dette syns jeg er en glimrende idé da det per dags dato mangler mange passende og fult dekkende ord i substitutt for de engelske som vi alle bruker til daglig. </p>
<p>Derfor anbefaler jeg alle som leser dette sette toppmuskelen i gang og bidra med noen gode ord til <a href="http://bza.no/norsk-webordbok/" title="Bza.no: Bidra til en norsk webordbok">webordboken hos Bza</a>. Alt man trenger å gjøre er å skrive inn en kommentar i skjemaet som du finner på linken som ble gitt tidligere.</p>
<p>Veldig bra initativ, bza!
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2007/bzas-webordbok-pa-norsk/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>PHP/MySQL: Hvordan legge prefiks på tabeller uten prefiks</title>
		<link>http://mikaelb.net/2007/phpmysql-hvordan-legge-prefiks-pa-tabeller-uten-prefiks/</link>
		<comments>http://mikaelb.net/2007/phpmysql-hvordan-legge-prefiks-pa-tabeller-uten-prefiks/#comments</comments>
		<pubDate>Fri, 28 Dec 2007 03:25:02 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>PHP / MySQL</category>
		<guid isPermaLink="false">http://mikaelb.net/2007/phpmysql-hvordan-legge-prefiks-pa-tabeller-uten-prefiks/</guid>
		<description><![CDATA[Siden det har vært veldig lite skriving på denne bloggen, tenkte jeg at jeg skulle bruke romjulen til å skrive noe. Jeg sitter her nå på vakt i militæret og har lite å gjøre. Det ble stilt et spørsmål på NWF hvordan en kunne sette prefiks på tabeller som mangler prefiks i en viss database. [...]]]></description>
			<content:encoded><![CDATA[<p>Siden det har vært veldig lite skriving på denne bloggen, tenkte jeg at jeg skulle bruke romjulen til å skrive noe. Jeg sitter her nå på vakt i militæret og har lite å gjøre. Det ble stilt et spørsmål på <acronym title="Norsk WebForum">NWF</acronym> hvordan en kunne sette prefiks på tabeller som mangler prefiks i en viss database. Dette er, såvidt jeg vet, ikke mulig å løse kun med å bruke spørringer i MySQL. Derfor måtte jeg til med 2 slags spørringer, og litt prossessering i <acronym title="Pre-Hypertext Processing">PHP</acronym>. </p>
<p>Vi benytter oss av spørringen</p>
<div class="syntax_hilite">
<div id="mysql-28">
<div class="mysql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">SHOW</span> TABLES </div>
</li>
</ol>
</div>
</div>
</div>
<p>
For å hente ut alle tabellene som er i databasen. Disse er det vi bruker for å sjekke om det er noen som ikke har prefiksen vi skal ha. Etter vi har funnet alle tabellene vi må rename bruker vi <code>RENAME TABLE</code> som kan endre navn på flere tabeller samtidig. </p>
<div class="syntax_hilite">
<div id="mysql-29">
<div class="mysql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">RENAME TABLE</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">table1 TO new_table1,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">table2 TO new_table2</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">-- ...osv i den retningen </span></div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Da skal det være veldig enkelt å hente ut nødvendig informasjon, bruke PHPs <code>strpos()</code> eller <code>preg_match()</code> (fordelen med preg_match() er at du kan vise til hvor i strengen du skal matche, som i vårt tilfelle er på starten) til å finne hvilke som ikke har ønsket prefiks.</p>
<p>Resultatet er som følger:</p>
<div class="syntax_hilite">
<div id="php-30">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Connect to the database and select</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/mysql_connect"><span style="color:#0000FF;">mysql_connect</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'localhost'</span>, <span style="color:#CC0000;">'***'</span>, <span style="color:#CC0000;">'***'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/mysql_select_db"><span style="color:#0000FF;">mysql_select_db</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'***'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">/**</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;"> * A function that returns a rename-query with </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;"> * all the tables that lack the prefix you </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;"> * set in the argument.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;"> *</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;"> * @param string $prefix</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;"> * @return mixed</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;"> */</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/function"><span style="color:#0000FF;">function</span></a> make_rename_command <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$prefix</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: red;">$mysql_result</span> = <a href="http://www.php.net/mysql_query"><span style="color:#0000FF;">mysql_query</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'SHOW TABLES'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: red;">$tables</span> = <a href="http://www.php.net/array"><span style="color:#0000FF;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Fetch all the tables in the databse</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#03B903;">while</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$row</span> = <a href="http://www.php.net/mysql_fetch_array"><span style="color:#0000FF;">mysql_fetch_array</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$mysql_result</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: red;">$tables</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color: red;">$row</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Start the MySQL-query</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: red;">$output</span> = <span style="color:#CC0000;">'RENAME TABLE '</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: red;">$all</span> = <span style="color:#006600;">true</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#03B903;">foreach</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$tables</span> <span style="color:#03B903;">as</span> <span style="color: red;">$table</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Check if the table has the prefix</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#03B903;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/preg_match"><span style="color:#0000FF;">preg_match</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'/^'</span>.<span style="color: red;">$prefix</span>.<span style="color:#CC0000;">'/'</span>, <span style="color: red;">$table</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// It doesn't so lets add it to the new</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// query...</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: red;">$output</span> .= <span style="color:#CC0000;">'`'</span>.<span style="color: red;">$table</span> . <span style="color:#CC0000;">'` TO `'</span> .</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <span style="color: red;">$prefix</span> . <span style="color: red;">$table</span> . <span style="color:#CC0000;">'`, '</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Not all the tables has the prefix </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: red;">$all</span> = <span style="color:#006600;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// If all the tables has the correct prefix, </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// skip returning a query</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#03B903;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$all</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#03B903;">return</span> <span style="color:#006600;">false</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Return the query</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#03B903;">return</span> <a href="http://www.php.net/substr"><span style="color:#0000FF;">substr</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$output</span>, <span style="color:#FF0000;color:#800000;">0</span>, -<span style="color:#FF0000;color:#800000;">2</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Check if there is something to rename</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#03B903;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$rename_query</span> = make_rename_command <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'new_'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: red;">$query</span> = <a href="http://www.php.net/mysql_query"><span style="color:#0000FF;">mysql_query</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$rename_query</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Check for a successfull query</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#03B903;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color: red;">$query</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.php.net/die"><span style="color:#0000FF;">die</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'MySQL-query failed: '</span> . <span style="color: red;">$rename_query</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Everyting went well.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#0000FF;">echo</span></a> <span style="color:#CC0000;">'ALl the tables where renamed.'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#03B903;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// There was nothing to do...</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span style="color:#0000FF;">echo</span></a> <span style="color:#CC0000;">'There<span style="color:#CC0000; font-weight:bold;">\'</span>s nothing to rename'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Kodene skal være godt kommenterte, og trenger derfor ingen forklaring. Det er jo mulig du en gang i fremtiden får bruk for dette, og ikke orker å gjøre det selv?
</p>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2007/phpmysql-hvordan-legge-prefiks-pa-tabeller-uten-prefiks/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Hvordan bruke regulære uttrykk i PHP</title>
		<link>http://mikaelb.net/2007/hvordan-bruke-regulaere-uttrykk-i-php/</link>
		<comments>http://mikaelb.net/2007/hvordan-bruke-regulaere-uttrykk-i-php/#comments</comments>
		<pubDate>Sun, 18 Nov 2007 13:32:45 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>PHP / MySQL</category>
		<guid isPermaLink="false">http://mikaelb.net/2007/hvordan-bruke-regulaere-uttrykk-i-php/</guid>
		<description><![CDATA[Etter at jeg skrev Hvordan lage regulære uttrykk for en del tid tilbake, tenkte jeg nå at jeg skulle skrive litt om hvordan man bruker reguløre uttrykk i PHP. Dette er hovedsakelig grunnet lenge siden forrige post, og noe respons på at forrige artikkel manglet dette.
Man kan samle bruksområdet til regulære uttrykk i 2 hovedgrupper. [...]]]></description>
			<content:encoded><![CDATA[<p>Etter at jeg skrev <a href="http://mikaelb.net/2007/hvordan-lage-regulaere-uttrykk/#comment-6415">Hvordan lage regulære uttrykk</a> for en del tid tilbake, tenkte jeg nå at jeg skulle skrive litt om hvordan man bruker reguløre uttrykk i <acronym title="Pre-Hypertext Processing">PHP</acronym>. Dette er hovedsakelig grunnet lenge siden forrige post, og noe respons på at forrige artikkel manglet dette.</p>
<p>Man kan samle bruksområdet til regulære uttrykk i 2 hovedgrupper. Disse er søk/matching og erstatting. Under søk/matching finner vi funksjoner som <code>preg_match ()</code> og <code>preg_match_all ()</code>. I den andre gruppen finner vi blant annet <code>preg_replace ()</code>. Det finnes også flere funksjoner, de kommer jeg tilbake til senere. Alt av regex går på manipulering av data. Det finnes også flere funksjoner i preg_* serien, men jeg kommer ikke til å gå igjennom alle av de. Jeg går igjennom 3 funksjoner, som er de som oftes blir brukt. Det er veldig lett å finne ut av resten når du kan disse grunnleggende tre. Det er bare å lære seg disse og se på forskjellene med de andre i <a href="http://php.net"><acronym title="Pre-Hypertext Processing">PHP</acronym> Manualen</a></p>
<p>Som dere kanskje ser er det <code>preg_*</code>-funksjoner som blir brukt til regulære uttrykk nå til dags. Tidligere ble det brukt <code>ereg*</code>-funksjoner, men de er nå utgått pga stor hastighetsforskjell. </p>
<h2>Søk/matching</h2>
<p>Dette brukes om du skal sjekke om noe (gjerne ukjent) eksisterer i en streng. Det blir da søking etter noe eller matche strenger som har en viss dynamikk i seg. I all hovedsak er det snakk om <code>preg_match()</code> og <code>preg_match_all()</code>.</p>
<p>Det er relativt liten forskjell på disse to. *_all blir brukt når det er forventet flere resultater av matchingen i mønstret på stringen du har satt. Du setter en tom array i et argument for å få resultatene du henter ut. Du bruker ikke *_all om du skal sjekke om noe eksisterer i en streng. Den returnerer antallet av matcher som oppstår, på samme måte som den vanlige preg_match funksjonen, og false ved feil, men så lenge du bruker den i en boolsk if-statment er det ikke noe poeng å bruke preg_match_all () siden alt over 1 er true, og det greier preg_match å gjøre selv. </p>
<h3>Noen eksempler på bruk av preg_match() og preg_match_all ()</h3>
<p>Nå i det siste har jeg brukt veldig mye regulære uttrykk mens jeg har jobbet på IMDb_Fetch. Der er det genialt å bruke regex. Du henter ut en ukjent informasjon som befinner seg i et visst mønster. </p>
<p>Skal jeg f.eks sjekke om det er tall i en streng, kan jeg bruke simpel boolsk returnering av preg_match. Det kan jeg da gjøre på dette viset:</p>
<div class="syntax_hilite">
<div id="php-36">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$string</span> = <span style="color:#CC0000;">'Hei, dette er en tekst med tall 1234'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#03B903;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color:#0000FF;">preg_match</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'/<span style="color:#CC0000; font-weight:bold;">\d</span>/'</span>, <span style="color: red;">$string</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Det er tall i strengen $string</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Dette vil da være true, siden vi finner tall i strengen. Dette er veldig simpel søking eller matching om du vil. Om jeg vil ha tallene som er i retur kan jeg legge til en tom array på et argument (tredje), som viser meg hva som blir funnet. </p>
<div class="syntax_hilite">
<div id="php-37">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$string</span> = <span style="color:#CC0000;">'Hei, dette er en tekst med tall 1234'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$matches</span> = <a href="http://www.php.net/array"><span style="color:#0000FF;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#03B903;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/preg_match"><span style="color:#0000FF;">preg_match</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'/[<span style="color:#CC0000; font-weight:bold;">\d</span>]+/'</span>, <span style="color: red;">$string</span>, <span style="color: red;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Det er tall i strengen $string</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://www.php.net/print_r"><span style="color:#0000FF;">print_r</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<span style="color:#FF9900; font-size: 0.9em; font-style: italic;">/* Viser:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">&nbsp; &nbsp; &nbsp; Array</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">&nbsp; &nbsp; &nbsp; (</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[0] =&gt; 1234</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">&nbsp; &nbsp; &nbsp; )</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">&nbsp; &nbsp;*/</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Dette er et kjapt eksempel på hvordan du kan se etter om noe finnes, og hente ut informasjon. Men hva om jeg har en lang streng med informasjon som jeg vil hente ut. </p>
<p>Tenk oss den fiktive problemstillingen at jeg har en liste av personer med alder, som jeg vil hente ut. Dette er da en ordnet liste fra et <acronym title="HyperText Markup Language">HTML</acronym>-dokument. Dokumentet ser slik ut:</p>
<div class="syntax_hilite">
<div id="html-38">
<div class="html">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/ol.html"><span style="color: #009933;">&lt;ol&gt;</span></a></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #009933;">&lt;li&gt;</span></a></span>Grete: 34 år<span style="color: #009900;"><span style="color: #009933;">&lt;/li&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #009933;">&lt;li&gt;</span></a></span>Hans Marius: 18 år<span style="color: #009900;"><span style="color: #009933;">&lt;/li&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><a href="http://december.com/html/4/element/li.html"><span style="color: #009933;">&lt;li&gt;</span></a></span>Espen Andreas Bergen: 74 år<span style="color: #009900;"><span style="color: #009933;">&lt;/li&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="color: #009933;">&lt;/ol&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Her vil jeg altså hente ut navn, og alder. Dette skal være gruppert for hver linje. Så jeg lager et mønster som går for en linje, og bruker preg_match_all () for å repitere mønsteret så jeg får hentet ut alle tre navnene. </p>
<div class="syntax_hilite">
<div id="php-39">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$string</span> = <span style="color:#CC0000;">'&lt;ol&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">&lt;li&gt;Grete: 34 år&lt;/li&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">&lt;li&gt;Hans Marius: 18 år&lt;/li&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">&lt;li&gt;Espen Andreas Bergen: 74 år&lt;/li&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$matches</span> = <a href="http://www.php.net/array"><span style="color:#0000FF;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Uttrykket følger det mønsteret jeg ser er på hver linje av det</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// relevante jeg vil hente ut. Det er noen særpreg som er statiske </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// på linjene. Dette er li-taggen, kolon og &quot;år&quot;. Da er det lett å hente </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// ut informasjonen.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$regex</span> = <span style="color:#CC0000;">'/&lt;li&gt;(?P&lt;name&gt;[<span style="color:#CC0000; font-weight:bold;">\w</span> ]*):<span style="color:#CC0000; font-weight:bold;">\s</span>*(?P&lt;age&gt;[<span style="color:#CC0000; font-weight:bold;">\d</span>]+)<span style="color:#CC0000; font-weight:bold;">\s</span>*år&lt;<span style="color:#CC0000; font-weight:bold;">\/</span>li&gt;/'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#03B903;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/preg_match_all"><span style="color:#0000FF;">preg_match_all</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$regex</span>, <span style="color: red;">$string</span>, <span style="color: red;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Det ble funnet resultat</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <a href="http://www.php.net/print_r"><span style="color:#0000FF;">print_r</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$matches</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Der bruker jeg <a href="http://mikaelb.net/2007/named-capture-grouping-i-regexp-php/">Named Capture Grouping</a> for å få bedre kontroll over resultatene, og få innbakt det i et eksempel også. Resultatet i $matches vil være noe følgende:</p>
<blockquote><p>
<code><br />
Array<br />
(<br />
    [0] => Array<br />
        (<br />
            [0] =>
<li>Grete: 34 år</li>
<p>            [1] =>
<li>Hans Marius: 18 år</li>
<p>            [2] =>
<li>Espen Andreas Bergen: 74 år</li>
<p>        )</p>
<p>    [name] => Array<br />
        (<br />
            [0] => Grete<br />
            [1] => Hans Marius<br />
            [2] => Espen Andreas Bergen<br />
        )</p>
<p>    [1] => Array<br />
        (<br />
            [0] => Grete<br />
            [1] => Hans Marius<br />
            [2] => Espen Andreas Bergen<br />
        )</p>
<p>    [age] => Array<br />
        (<br />
            [0] => 34<br />
            [1] => 18<br />
            [2] => 74<br />
        )</p>
<p>    [2] => Array<br />
        (<br />
            [0] => 34<br />
            [1] => 18<br />
            [2] => 74<br />
        )</p>
<p>)</p>
<p></code>
</p></blockquote>
<p>Sånn er det lett å hente ut informasjonen vi vil med å bruke $matches['name'][0] for navnet på første personen og $matches['age'][0] for alderen på første personen. Veldig lett å finne frem. Da har vi søkt etter data om ukjente personer og hentet ut ukjent informasjon med regulære uttrykk. </p>
<h2>Erstatting av ukjent innhold</h2>
<p>Hele poenget med regexp er jo at du skulle kunne behandle informasjon som kanskje er ukjent for deg. Du vet noen kriterier, men ikke det nøyaktige innholdet, som kan variere fra gang til gang. Om det ikke hadde vært en viss dynamikk i det kunne du ha brukt andre funksjoner som strpos() eller str_replace() for erstatting. </p>
<p>La oss si at jeg skal lage brukervennlige adresser ut av tittel. Slik som f.eks wordpress gjør, eller mange, mange andre <acronym title="Content Management System">CMS</acronym>. Dette er en veldig vanlig problemstilling. Da må jeg først se hvilke tegn som kan brukes. Dette er kun vanlige små alfa-bokstaver (a-z), tall, bindestrek og understrek. Dette er det mest vanlige for titler. Det vi vil gjøre da er å fjerne alt det andre.</p>
<div class="syntax_hilite">
<div id="php-40">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$string</span> = <span style="color:#CC0000;">'Min fiNe tiTtel med 123, ØÆÅ og @@#$'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Gjør først alt til små bokstaver. ØÆÅ blir </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// ikke tatt av strtolower (), så vi må gjøre det selv</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$string</span> = <a href="http://www.php.net/strtolower"><span style="color:#0000FF;">strtolower</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$string</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$scandic_letters</span> = <a href="http://www.php.net/array"><span style="color:#0000FF;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'Ø'</span>, <span style="color:#CC0000;">'Æ'</span>, <span style="color:#CC0000;">'Å'</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#CC0000;">'ø'</span>,<span style="color:#CC0000;">'æ'</span>,<span style="color:#CC0000;">'å'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$scandic_transformed</span> = <a href="http://www.php.net/array"><span style="color:#0000FF;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'oe'</span>, <span style="color:#CC0000;">'ae'</span>, <span style="color:#CC0000;">'aa'</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;<span style="color:#CC0000;">'oe'</span>, <span style="color:#CC0000;">'ae'</span>, <span style="color:#CC0000;">'aa'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Først lager vi om de ikke-godkjente </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// bokstavene til noe som kan forstås</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Her er det statiske verdier så vi bruker </span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// str_replace</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$title</span> = <a href="http://www.php.net/str_replace"><span style="color:#0000FF;">str_replace</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: red;">$scandic_letters</span>, </div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$scandic_transformed</span>, <span style="color: red;">$string</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Så gjenstår det å fjerne alt det som ikke</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// er tillatt og gjøre om mellomrom til -</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$title</span> = <a href="http://www.php.net/preg_replace"><span style="color:#0000FF;">preg_replace</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'/[<span style="color:#CC0000; font-weight:bold;">\s</span>]+/'</span>, <span style="color:#CC0000;">'-'</span>, <span style="color: red;">$title</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Fjerne ugyldige tegn</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: red;">$title</span> = <a href="http://www.php.net/preg_replace"><span style="color:#0000FF;">preg_replace</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'/[^<span style="color:#CC0000; font-weight:bold;">\w</span>-]/'</span>, <span style="color:#CC0000;">''</span>, <span style="color: red;">$title</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#0000FF;">echo</span></a> <span style="color: red;">$title</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9900; font-size: 0.9em; font-style: italic;">// Vil vise: min-fine-tittel-med-123-oeaeaa-og-</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#000000; font-weight:bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Da har vi oppnådd det vi ville. Det er en dynamikk i det, og den låser seg ikke til den faste tittelen, men på alle tekster og du kan kjøre alt igjennom der for å få en gyldig streng som kan brukes i en tittel. </p>
<p>Dette var en <strong>veldig</strong> kjapp gjennomgang på hvordan en kan bruke regulære uttrykk i <acronym title="Pre-Hypertext Processing">PHP</acronym>. Jeg har desverre ikke mer tid til å skrive noe i dag. </age></name></li>]]></content:encoded>
			<wfw:commentRSS>http://mikaelb.net/2007/hvordan-bruke-regulaere-uttrykk-i-php/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Is, kulde og kruttpulver</title>
		<link>http://mikaelb.net/2007/is-kulde-og-kruttpulver/</link>
		<comments>http://mikaelb.net/2007/is-kulde-og-kruttpulver/#comments</comments>
		<pubDate>Fri, 12 Oct 2007 22:50:50 +0000</pubDate>
		<dc:creator>Mikael Brevik</dc:creator>
		
	<category>Blogg</category>
		<guid isPermaLink="false">http://mikaelb.net/2007/is-kulde-og-kruttpulver/</guid>
		<description><![CDATA[Som mange sikkert har fått med seg soner jeg min tid i Garden nå for tiden. Dette vil si at jeg foreløpig har null tid til å skrive her om noe som helst. Jeg vet denne posten strider totalt i mot det bza har skrevet om å ikke drepe sin egen blogg, men jeg føler [...]]]></description>
			<content:encoded><![CDATA[<p>Som mange sikkert har fått med seg soner jeg min tid i Garden nå for tiden. Dette vil si at jeg foreløpig har null tid til å skrive her om noe som helst. Jeg vet de