Hi,
How I can detect the length of variable value?
Also I want to check the same variable for Uppercase letters. If they are - script tells me.
Thanks in Advance![]()
Hi,
How I can detect the length of variable value?
Also I want to check the same variable for Uppercase letters. If they are - script tells me.
Thanks in Advance![]()
Last edited by auriaks; 03-27-2010 at 12:07 PM.
To find the string length, just simply use strlen() around the variable, as above. $len is equal to 18 in this example.PHP Code:<?php
$str = "contains UpperCASE";
$len = strlen($str);
$pattern = preg_match('/[A-Z]+/', $str);
if($pattern)
echo 'Uppercase Detected';
?>
I'm terrible at regex, but the above pattern seems to do the job.
I'm not sure what your purpose is, but you can also use strtolower() or strtoupper() to convert to all upper/lowercase and then you don't have to worry about inconsistencies if you are checking for that reason.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
{CWoT - Riddle } {Freelance Copywriter} {Learn to Write}
Follow Me on Twitter: @InkingHubris
PHP Code:$result = mysql_query("SELECT finger FROM hand WHERE id=3");
echo $result;
Almost always when I see a request for this it is to confirm whether a complex password was submitted; one that has upper and lowercase letters and numbers.
To choose the lesser of two evils is still to choose evil. My personal site
If that, then you can confirm it in this way:
if ($p!=strtolower($p)&&$p!=strtoupper($p)) { ...complex... }
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
^umm... ?
do you mean?PHP Code:<?php
$str = 'UPPERCASE & lowercase';
if(preg_match('/[A-Z]+/', $str) && preg_match('/[a-z]+/', $str)){ /* all is well */ }
?>
If the goal is to see if there are BOTH lowercase and uppercase, then using the two functions in my post above will work-- basically you're checking that it's already not all lowercase and not all uppercase.
What you're doing could never return true, I believe. (Though I'm no good with regex either.)
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Thanks, for all the information.
The aim is to check if word is without uppercases![]()
Without uppercases?
Do this:
if ($p==strtolower($p)) { ...it's ok... }
Or, you can just do this:
$p = strtolower($p);
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Bookmarks