Wildan Muhlis
Wildan Muhlis

Reputation: 1603

ucwords doesn't work when After Slash (/) Symbol

I write this code

echo ucwords('online/offline');

expected result : Online/Offline

result: Online/offline

How to make first letter after slash symbol become capital letter without adding spaces?

Upvotes: 4

Views: 700

Answers (3)

Sachin Sarola
Sachin Sarola

Reputation: 1041

because ucwords() Convert the first character of each word to uppercase and each word differ by space if you used this one echo ucwords('online/offline', '/');

than not work for

'echo ucwords ('online offline','/')`

you should pass all character that separate the word for e.g

echo ucwords('online/offline', '/, ');

Upvotes: 1

Razon Yang
Razon Yang

Reputation: 454

ucwords supports delimiter parameter:

echo ucwords('online/offline', '/');

Upvotes: 3

Eddie
Eddie

Reputation: 26844

You can add delimiters on the second paremeter of ucwords

echo ucwords('online/offline', '/');

This will result to:

Online/Offline 

Documentation: http://php.net/manual/en/function.ucwords.php

The optional delimiters contains the word separator characters.

Upvotes: 9

Related Questions