<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Kastang &#187; Parsing PHP</title>
	<atom:link href="http://kastang.com/blog/tag/parsing-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://kastang.com</link>
	<description>Ramblings of a Geek</description>
	<lastBuildDate>Sat, 11 Jun 2011 00:30:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Parsing the WoW Armory &#8211; Part 1</title>
		<link>http://kastang.com/blog/2010/01/parsing-the-wow-armory-part-1/</link>
		<comments>http://kastang.com/blog/2010/01/parsing-the-wow-armory-part-1/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 22:17:35 +0000</pubDate>
		<dc:creator>Josh</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[WoW]]></category>
		<category><![CDATA[Armory]]></category>
		<category><![CDATA[Parsing PHP]]></category>

		<guid isPermaLink="false">http://kastang.com/?p=234</guid>
		<description><![CDATA[Today I pulled a list of every character in We Know from the WoW Armory in 5 lines of code. &#60; ?PHP ini_set&#40;&#34;user_agent&#34;, &#34;Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8&#34;&#41;; $url='http://www.wowarmory.com/guild-info.xml?r=Eitrigg&#38;gn=We+Know'; $xml = simplexml_load_file&#40;$url&#41;; &#160; foreach&#40;$xml-&#62;guildInfo-&#62;guild-&#62;members-&#62;character as $char&#41; echo $char&#91;'name'&#93;.&#34; - &#34;.$char&#91;'level'&#93;.&#34;&#60;br /&#62;&#34;; ?&#62; I never realized how easy is was [...]]]></description>
			<content:encoded><![CDATA[<p>Today I pulled a list of every character in We Know from the WoW Armory in 5 lines of code.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?PHP
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;user_agent&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$url</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'http://www.wowarmory.com/guild-info.xml?r=Eitrigg&amp;gn=We+Know'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guildInfo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">members</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">character</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; - &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'level'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>I never realized how easy is was to pull information from the WoW Armory until now. My method has its obvious flaws, such as the output is in no obvious order. I modified my original script to sort the list in ABC order and added a $server and $guild variable to allow for easy modification. Below is a more refined version, in under 15 lines of code the pulled list is sorted in ABC order and displayed.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?PHP
<span style="color: #990000;">ini_set</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;user_agent&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Mozilla/5.0 (X11; U; Linux i686; pl-PL; rv:1.9.0.2) Gecko/20121223 Ubuntu/9.25 (jaunty) Firefox/3.8&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$server</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Eitrigg&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$guild</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;We+Know&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$url</span><span style="color: #339933;">=</span><span style="color: #0000ff;">'http://www.wowarmory.com/guild-info.xml?r='</span><span style="color: #339933;">.</span><span style="color: #000088;">$server</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;gn='</span><span style="color: #339933;">.</span><span style="color: #000088;">$guild</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$xml</span> <span style="color: #339933;">=</span> <span style="color: #990000;">simplexml_load_file</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xml</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guildInfo</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guild</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">members</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">character</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$char</span><span style="color: #009900;">&#41;</span>
        <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; - &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$char</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'level'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;br /&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">sort</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$i</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$i</span><span style="color: #339933;">++;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This script is just a quick and dirty way to accomplish the simple task of pulling names from the WoW Armory. I would recommend against using this in a production environment without some sort of cache/database option implemented.</p>
]]></content:encoded>
			<wfw:commentRss>http://kastang.com/blog/2010/01/parsing-the-wow-armory-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

