Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Question First: Am i going about this the wrong way?
I had trouble braking from my for each with a conditional if inside. I wrote this just to save CPU Time yet i could not brake from my foreach.
I am trying to comply with with Active Directory strict password enforcement and i don't believe in having maximum length passwords. As i have found some websites have Maximum length requirements.
foreach(count_chars($new_password, 1) as $key => $value){//Strength Test Results can be derived from $value
if(!ctype_upper(chr($key))){$check_upper=1;}//if Upper-case
if(!ctype_lower(chr($key))){$check_lower=1;}//if Lower-case
if(!ctype_digit(chr($key))){$check_digit=1;}//if Numeric
if(!ctype_punct(chr($key))){$check_punct=1;}//if Symbol
if($check_upper + $check_lower + $check_digit + $check_punct>= 3){
break;
}//Save us from checking the entire string
}
You use the wrong keyword! It should mean break
foreach(count_chars($new_password, 1) as $key => $value){//Strength Test Results can be derived from $value
if(!ctype_upper(chr($key))){$check_upper=1;}//if Upper-case
if(!ctype_lower(chr($key))){$check_lower=1;}//if Lower-case
if(!ctype_digit(chr($key))){$check_digit=1;}//if Numeric
if(!ctype_punct(chr($key))){$check_punct=1;}//if Symbol
if($check_upper + $check_lower + $check_digit + $check_punct>= 3){
break;
}//Save us from checking the entire string
}
Well that's simple: break
Brake is what a car does.
http://php.net/manual/en/control-structures.break.php
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I'm trying to check if the $field['message'] is less than 5 letters and then check again if it's more than 100 letters, but I'm not passing the first rule - it's output the result for the $field['message'] < 5 - why?
} elseif (strlen($field['message'] < 5)) {
// some output for < 5 case
} elseif (strlen($field['message'] > 100)) {
// some output for > 100 case
}
And a result is that if I use less or more than 5 letters, I'm getting the same output for < 5 case.
What am I doing wrong here? Is it because of the array?
elseif (strlen($field['message'] < 5))
You put the parentheses in wrong places. Should be:
elseif (strlen($field['message']) < 5)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
The title is a bit confusing, but the error which I have is -
$xml="<Contacts>";
for($i=0;$i<count($results['records']);$i++){
$xml. = "<Contact>
<Name>".$results['records'][$i]['name']."</Name>";
}
$xml.="</Contacts>";
When I try to add something to string (concatenate) I get 500 Internal server error. I believe that problem is in " $results['records'][$i]['name']". I think the solution is to replace JSON value with variable and enclose it in {}...maybe I am wrong, i don't know.
UPD:
if I "echo ".$results['records'][$i]['name'].""; It works fine.
You have a string concatenation (.=) syntax error. Change
$xml. = "<Contact>
to
$xml .= "<Contact>
I'm strictly answering the question about the "string concatenation" PHP error. No downvotes for anything except this point, please. But yes, try not to generate XML manually. I closed </Contact>s for you below.
$xml="<Contacts>";
for ($i = 0; $i < count($results['records']); $i++) {
$xml .= "<Contact><Name>".$results['records'][$i]['name']."</Name></Contact>";
}
$xml.="</Contacts>";
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Trying to fetch the first URL field from an array of them that comes from a JSON I have decoded but I get this error:
Parse error: syntax error, unexpected '[' in C:\blabla
foreach($data-> images as $data2) {
print_r(images[0]['url']);
}
I hope its enough of my code to work out what I am doing wrong?
Added: I would like the first "url" and it was getting the last one hence why I am changing the code and trying to debug it here.
Within your foreach you use the variable name you specified in the definition:
So something like...
foreach($data->images as $data2) {
print_r($data2[0]['url']);
}
Although, depending on the structure of the array, I'd imagine that you don't need the number, so it might be:
foreach($data->images as $data2) {
print_r($data2['url']);
}
If you wanted to loop through the values by a number, you'd use a for loop
for ($i = 0; $i <= count($data->images); $i++)
{
print_r($data->images[$i]);
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I know that there are several questions about this issue, but this is a particullar case...
In the following code (in the the first and the last line) I have to replace split with preg_split, but I think something else needs to be changed too.
Please tell me what should I change in the code for it to work, and the theory behind this change, i.e. the gereral idea behind switching between split and preg_split. The code which needs the transition is:
$opt = split("_",$key);
if($opt[0]=="id" && $val!="0" && $val!=""){
some queries
$shuffle=split("_",$_POST['all_'.$i]);
Use explode instead of split. Your code should look like this :
$opt = explode("_",$key);
if($opt[0]=="id" && $val!="0" && $val!=""){
some queries
$shuffle=explode("_",$_POST['all_'.$i]);
Documentation : http://fr2.php.net/explode
PHP is in the process of dropping an older POSIX-compatible regex extension in favour of the newer PCRE extension. This means that older functions like split() and ereg() will be removed in time.
The PCRE equivalent for split() is preg_split(), which has a modified syntax. For your code you'd use:
$opt = preg_split("/_/",$key);
However, a Regex function is a heavyweight tool and isn't required here. You just need explode(), like this:
$opt = explode("_",$key);
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
**Update**
Fixed : http://codepad.org/6pB0WUm5
by http://stackoverflow.com/users/476/deceze
I have two codes, basically is same, but why, I got different output?
function domain_value($domain)
{
$split_domain = str_split($domain);
$ord_count = NULL;
foreach($split_domain as $key=>$value)
{
$ord_count += ord($value);
}
return $ord_count;
}
echo domain_value('abc');
and
echo ord('a')+ord('b')+ord('c');
Output
first output : 294
second output: 98
And what happens when you use:
echo ord('a')+ord('b')+ord('c');
which is probably what you intended in that second one :-)
In other words, you appear to have left the ord of the final part of the expression.
In fact, the only way you would normally get 98 would be with:
echo ('a')+ord('b')+('c')
(with ord only on the second term) so you may want to check again. If, as you seem to now indicate, you're using ord on each term, that works fine for me.
Both of them return 294 from 97 + 98 + 99, the ASCII values for a, b and c.