<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.refactormycode.com,2007:users1718</id>
  <link type="application/atom+xml" href="http://www.refactormycode.com/users/1718" rel="self"/>
  <title>paulswansea.myopenid.com</title>
  <updated>Wed Aug 25 20:45:55 -0700 2010</updated>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code1419</id>
    <published>2010-08-25T20:45:55-07:00</published>
    <updated>2010-09-16T06:15:04-07:00</updated>
    <title>[PHP] convert single itemed sub-arrays into string</title>
    <content type="html">&lt;p&gt;I tried using array_walk to search through a multidimensional array (5 levels deep) and find any arrays that contain a single item, and if so, convert the array to a string, but it didn't work, can someone re-factor the code, possibly give me a solution that can be as many levels deep and still turn single itemed arrays into a string?&lt;/p&gt;

&lt;pre&gt;&amp;lt;?php
foreach($final as $key =&amp;gt; $val) {
    if (is_array($val) &amp;amp;&amp;amp; count($val) == 1) $final[$key] = $val[0];
    if (is_array($val))			
    foreach ($val as $skey=&amp;gt;$sval) {
        if (is_array($sval) &amp;amp;&amp;amp; count($sval) == 1) $final[$key][$skey] = $sval[0];
        if (is_array($sval))
        foreach($sval as $sskey=&amp;gt;$ssval) {
            if (is_array($ssval) &amp;amp;&amp;amp; count($ssval) == 1) $final[$key][$skey][$sskey] = $ssval[0];
            if (is_array($ssval))
            foreach($ssval as $ssskey=&amp;gt;$sssval) {
                if (is_array($sssval) &amp;amp;&amp;amp; count($sssval) == 1) $final[$key][$skey][$sskey][$ssskey] = $sssval[0];
            }
        }
    }
}
?&amp;gt;&lt;/pre&gt;</content>
    <author>
      <name>paulswansea.myopenid.com</name>
      <email>sendtoswansea@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1419-convert-single-itemed-sub-arrays-into-string" rel="alternate"/>
  </entry>
  <entry>
    <id>tag:www.refactormycode.com,2007:Code1169</id>
    <published>2010-02-05T16:07:00-08:00</published>
    <updated>2010-05-03T00:44:03-07:00</updated>
    <title>[PHP] Trimming excess from string</title>
    <content type="html">&lt;p&gt;I'm trying to get an input string to get rid of all characters except alpha-numerics, hyphen and a space, then the result i would like any hyphens at the start and at the end removed, also, if there are more than one hyphen in a row, to just replace it with one, and change the whole thing to lower case e.g :&lt;/p&gt;

&lt;p&gt;-!! This is a &amp;quot;**Test-  -string**&amp;quot; !!!!-&lt;/p&gt;

&lt;p&gt;results to :&lt;/p&gt;

&lt;p&gt;this-is-a-test-string&lt;/p&gt;

&lt;p&gt;The code works fine, but it seems a bit long-winded the way i've done it, can this code be refactored at all?
&lt;/p&gt;

&lt;pre&gt;$outputstr =  preg_replace('/[-]{2,}/','-',trim(strtolower(str_replace(' ','-',preg_replace('/[^A-Z0-9- ]+/i','',$inputstr))),'-'));
&lt;/pre&gt;</content>
    <author>
      <name>paulswansea.myopenid.com</name>
      <email>sendtoswansea@hotmail.com</email>
    </author>
    <link type="text/html" href="http://www.refactormycode.com/codes/1169-trimming-excess-from-string" rel="alternate"/>
  </entry>
</feed>

