1

is it possible in laravel to change string like this:

"This Is String" to "this-is-string" ?

In laravel doc. I have only found this:

$snake = snake_case('fooBar');

// foo_bar

Thank you very much for your help :)

1
  • Why not just use PHP? See @Fabien's answer below. Commented Jul 17, 2014 at 8:43

3 Answers 3

7

If you want to do it in Laravel though, you could call:

Str::slug('This Is String');

For more info visit API: http://laravel.com/api/source-class-Illuminate.Support.Str.html#247-270

Sign up to request clarification or add additional context in comments.

1 Comment

Exactly what I was searching for :) Thank you very much :)
3

I don't know Laravel but you can try this :

<?php 
$string = "This Is String"
$string = strtolower(str_replace(" ", "-", $string)); // "this-is-string"
?>

2 Comments

You beat me to it. I couldn't type fast enough.
ok it's not laravel, but does the job :) thx for your help :)
2

try this :

return Str::slug('This Is String');

//this-is-string

doc : http://three.laravel.com/docs/strings / http://laravel.com/api/source-class-Illuminate.Support.Str.html#247-270

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.