<?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>chrishorsnell.co.uk &#187; Web</title>
	<atom:link href="http://www.chrishorsnell.co.uk/category/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrishorsnell.co.uk</link>
	<description>The ramblings of a techie / geek</description>
	<lastBuildDate>Mon, 24 May 2010 14:08:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Regular Expression for variable names</title>
		<link>http://www.chrishorsnell.co.uk/2010/05/regular-expression-for-variable-names/</link>
		<comments>http://www.chrishorsnell.co.uk/2010/05/regular-expression-for-variable-names/#comments</comments>
		<pubDate>Mon, 24 May 2010 14:08:53 +0000</pubDate>
		<dc:creator>mort</dc:creator>
				<category><![CDATA[Geeking]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.chrishorsnell.co.uk/?p=78</guid>
		<description><![CDATA[So I needed to grab all variables from a script to do various things with, and spent a while tracking down the regular expression to grab valid variable names. The official page on Regular Expression for variable names states &#8216;A     valid variable name starts with a letter or underscore, followed  [...]]]></description>
			<content:encoded><![CDATA[<p>So I needed to grab all variables from a script to do various things with, and spent a while tracking down the regular expression to grab valid variable names. The official page on <a href="http://docs.php.net/manual/en/language.variables.basics.php">Regular Expression for variable names</a> states &#8216;A     valid variable name starts with a letter or underscore, followed     by any number of letters, numbers, or underscores.&#8217;, which is purely the labeling rules for everything after the $.</p>
<p>As well as this we need to also tell it to look for the $ itself, and to output an array of the variables and just the variable names.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px;">http://docs.php.net/manual/en/language.variables.basics.php</div>
<p><code>$string = '$Lorem ipsum dolor sit $amet, consectetur '$adipiscing' elit. Vestibulum nulla magna, tristique sit amet tempor ornare, iaculis ut sapien.';<br />
preg_match_all('/[\$]([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)/',$</code><code>string</code><code>,$matches);<br />
print_r($matches);</code></p>
<p>This should output:<br />
<code>Array ( [0] =&gt; Array ( [0] =&gt; $Lorem [1] =&gt; $amet [2] =&gt; $adipiscing ) [1] =&gt; Array ( [0] =&gt; Lorem [1] =&gt; amet [2] =&gt; adipiscing ) ) </code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishorsnell.co.uk/2010/05/regular-expression-for-variable-names/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

