Answers.Body: <p>I guess you could make use of some php functions to do this:</p>
  
  <p><code>$string = 'Hello there';</code></p>
  
  <p>First <a href="http://php.net/manual/en/function.explode.php" rel="nofollow">explode</a> the string using a space as the seperator</p>
  
  <p><code>$result = explode(" ", $string);</code></p>
  
  <p>This will give you an array like <code>array(0 =&gt; 'Hello' 1 =&gt; 'there')</code></p>
  
  <p>Then you can <a href="http://php.net/manual/en/function.implode.php" rel="nofollow">implode</a> the array, using an <code>-</code> as the "glue" </p>
  
  <p><code>$result = implode('-', $result);</code></p>
  
  <p>Which will then give you <code>Hello-there</code></p>
  
  <p>Then use <a href="http://php.net/manual/en/function.strtolower.php" rel="nofollow">strtolower</a> to make it lowercase</p>
  
  <p><code>$result = strtolower($result);</code></p>
  
  <p>To simplify this, you can just do it all at once</p>
  
  <p><code>$result = strtolower(implode('-',explode(" ", 'Hello there')));</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T10:33:22.880Z
Answers.LastActivityDate: 2016-01-29T10:33:22.880Z
Answers.UserDisplayName: Alec Ritson
Answers.Body: <p>You can actually use the <a href="https://craftcms.com/classreference/helpers/StringHelper#toKebabCase-detail" rel="nofollow">StringHelper::toKebabCase</a>  function for this:</p>
  
  <pre class="lang-php prettyprint-override"><code>$string = 'Hello there';
  $result = StringHelper::toKebabCase($string);
  // =&gt; 'hello-there'
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T11:10:42.017Z
Answers.Text: Can you give an example on how to call this function please?
Answers.UserDisplayName: Adam Menczykowski
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T11:14:57.913Z
Answers.Text: Trying this: $urlslug = toKebabCase($member->membersCompanyName); results in: Call to undefined function Craft\toKebabCase()
Answers.UserDisplayName: Adam Menczykowski
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T13:00:31.110Z
Answers.Text: @AdamMenczykowski Just updated the answer with an example.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T13:00:57.880Z
Answers.Text: $string = StringHelper::toKebabCase('test this string'); does it!
Answers.UserDisplayName: Adam Menczykowski
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-29T10:38:19.327Z
Answers.LastActivityDate: 2016-01-29T13:00:03.723Z
Answers.LastEditDate: 2016-01-29T13:00:03.723Z
Answers.UserDisplayName: chris
Body: <p>I want to convert a String into kebab-case.</p>
  
  <pre><code>'Hello there' -&gt; 'hello-there'
  </code></pre>
  
  <p>I'm working in the Element API, so haven't got the pleasure of using the simple Twig filter. I guess there is a way of doing it in PHP. Any suggestions? Thank you</p>
  
Tags: <filter><plugin-elementapi>
Title: Element API - 'String' to 'kebab-case'
ThreadText: # Element API - 'String' to 'kebab-case'
  
  (Asked by: username_0 on 2016-01-29)
  
  I want to convert a String into kebab-case.
  
  ```
  'Hello there' -> 'hello-there'
  
  ```
  
  I'm working in the Element API, so haven't got the pleasure of using the simple Twig filter. I guess there is a way of doing it in PHP. Any suggestions? Thank you
  
  **Tags:** filter, plugin-elementapi
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2016-01-29. Score: 7 | Accepted answer
  
  You can actually use the [StringHelper::toKebabCase](https://craftcms.com/classreference/helpers/StringHelper#toKebabCase-detail) function for this:
  
  ```php
  $string = 'Hello there';
  $result = StringHelper::toKebabCase($string);
  // => 'hello-there'
  
  ```
  
  > **Comments:**
  > **username_0**: Can you give an example on how to call this function please?  
  > **username_0**: Trying this: $urlslug = toKebabCase($member->membersCompanyName); results in: Call to undefined function Craft\toKebabCase()  
  > **username_3**: @username_0 Just updated the answer with an example.  
  > **username_0**: $string = StringHelper::toKebabCase('test this string'); does it!  
  
  ---
  
  ### Answer by username_1 on 2016-01-29. Score: 1
  
  I guess you could make use of some php functions to do this:
  
  `$string = 'Hello there';`
  
  First [explode](http://php.net/manual/en/function.explode.php) the string using a space as the seperator
  
  `$result = explode(" ", $string);`
  
  This will give you an array like `array(0 => 'Hello' 1 => 'there')`
  
  Then you can [implode](http://php.net/manual/en/function.implode.php) the array, using an `-` as the "glue"
  
  `$result = implode('-', $result);`
  
  Which will then give you `Hello-there`
  
  Then use [strtolower](http://php.net/manual/en/function.strtolower.php) to make it lowercase
  
  `$result = strtolower($result);`
  
  To simplify this, you can just do it all at once
  
  `$result = strtolower(implode('-',explode(" ", 'Hello there')));`
  
  
  ---
  
  