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.
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 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
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
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 am getting a value from database 67.00€ .I need to multiple this value with an integer. So, used explode function of php to convert this to array and stored it in a variable $result.
print_r() is as follows:
Array
(
[0] => 67
[1] => 00€
)
Now, if i'm multiplying the first value of this array with any value, result is always 0.
like:
$result[0]*12
i also tried to convert the first value to integer by using (int) $result[0] and intval($result[0]). Both output 0
What i am doing wrong?
Try this:
intval($result[0])* 12
I have tried this and it worked for me. Please create a new file and run in localhost other that your project.
test.php
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$str = '67.00$';
$result = explode('.',$str);
print_r($result);
$ans= intval($result[0])*12; // or $ans=($result[0])*12; both worked
echo 'Answer-->'.$ans; // 804
?>
I don't know what you doing wrong. I hope from this you may able to detect your err.
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 9 years ago.
Improve this question
Im trying to json_decode the following:
"main":{
"temp":9.04,
"temp_min":9.04,
"temp_max":9.04,
"pressure":938.13,
"sea_level":1037.57,
"grnd_level":938.13,
"humidity":87
},
"weather":[
{
"id":801,
"main":"Clouds",
"description":"few clouds",
"icon":"02d"
}
],
$result = json_decode($json);
$temp = $result->main->temp; //is displaying the data
however
$id = $result->weather->id; //is not displaying anything
all i can see is difference that te second one have an extra "[]"
can you help me telling how can i get weather->id from that json, thank you
The weather element is an array: it contains a list of elements. To get what you want from that exact example you would want:
$id = $result->weather[0]->id;
You also might want to think about what you want to happen if there is more than one element in that array, or if there are zero.