Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple strtolower not working

Tags:

php

buddypress

Im sure this is something obvious i'm missing but I have a string 'GB' that is stored as $str and is then echoed out using strtolower...

$str = bp_member_profile_data('field=Country');
echo strtolower($str);

I am expecting to see 'gb' (lowercase) but the output is still 'GB' (uppercase)

What could I be doing wrong?

UPDATE Turns out That the issue lied with bp_member_profile_data, this is a BuddyPress PHP function that automatically echos so it was ignoring the strtolower - Thanks to everybody for helping to narrow it down!

like image 223
fightstarr20 Avatar asked Mar 30 '13 23:03

fightstarr20


People also ask

What does strtolower() mean?

The strtolower() function converts a string to lowercase. Note: This function is binary-safe. Related functions: strtoupper() - converts a string to uppercase. lcfirst() - converts the first character of a string to lowercase.

How do I use Strtolower?

The strtolower() function is used to convert a string into lowercase. This function takes a string as parameter and converts all the uppercase english alphabets present in the string to lowercase. All other numeric characters or special characters in the string remains unchanged.

How to convert string lowercase to uppercase in PHP?

The strtoupper() function converts a string to uppercase. Note: This function is binary-safe. Related functions: strtolower() - converts a string to lowercase.

What is Ucfirst PHP?

The ucfirst() function converts the first character of a string to uppercase. Related functions: lcfirst() - converts the first character of a string to lowercase. ucwords() - converts the first character of each word in a string to uppercase. strtoupper() - converts a string to uppercase.


2 Answers

Try to use:

mb_strtolower($str);

This may work.

From PHP Manual:

If the input string is in different language that server locale, then you should use mb_strtolower() function.

The function prototype is:

string mb_strtolower ( string $str [, string $encoding = mb_internal_encoding() ] )

You could try adding the appropriate encoding.

The encoding parameter is the character encoding. If it is omitted, the internal character encoding value will be used.

like image 81
Jean Avatar answered Oct 22 '22 19:10

Jean


Check out buddy press bp_member_profile_data() function, it echoes:

function bp_member_profile_data( $args = '' ) {
    echo bp_get_member_profile_data( $args );
}

You might want to use bp_get_member_profile_data()

like image 4
enapupe Avatar answered Oct 22 '22 18:10

enapupe