Jakub Kohout
Jakub Kohout

Reputation: 1944

Laravel string conversion

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 :)

Upvotes: 1

Views: 4244

Answers (3)

Hary Purnomo
Hary Purnomo

Reputation: 64

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

Upvotes: 2

Fabien Papet
Fabien Papet

Reputation: 2319

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

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

Upvotes: 3

Tom
Tom

Reputation: 3664

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

Upvotes: 7

Related Questions