Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have the following code and output
for ($i=0;$i<=100;$i++)
if ($i % 2!=0)
echo $i + "";
?>
13579111315171921232527293133353739414345474951535557596163656769717375777981838587899193959799
The problem is that there is no space between the numbers. How do I add this space
Change echo $i + ""; to echo $i . " ";
for ($i=0;$i<=100;$i++)
if ($i % 2!=0)
echo "$i ";
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Just need help fixing this php code
if ($cmtx_set_name_value == "anonymous")
{
$cmtx_set_name_value = ""
}
thanks
Try adding ; after the assignment.
$cmtx_set_name_value = "";
your code is work fine just put ; to end of line
if ($cmtx_set_name_value == "anonymous"){
$cmtx_set_name_value = "" ; }
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have this PHP code that displays values in an array:
$header->from[0]->mailbox . "#" . $header->from[0]->host;
whats the best way to loop round to get [1], [2], [3], etc...
You can do it through a foreach loop like this:
foreach ($header->from as $from){
echo $from->mailbox . "#" . $from->host;
}
If you want to process the first element outside the loop, then you can use array_shift:
$first_from = array_shift($header->from);
$first_from->mailbox . "#" . $first_from->host;
foreach ($header->from as $from){
echo $from->mailbox . "#" . $from->host;
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Why can't I call this function with the function and increment it's argument?
It seems to loop endlessly without $i incrementing.
function loopy($i) {
loopy($i+1);
echo $i.'...';
if ($i >=5) return true;
}
Because the if statement needs to go before calling the function again to stop it beign an infinite loop:
function loopy($i) {
if ($i >=5) return true;
loopy($i+1);
echo $i.'...';
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to see if the last two characters/digits in a filename are numbers in PHP.
if (CODE HERE) {
// runs script because last two characters are numbers
}
This should set it off:
http://www.nws.noaa.gov/weather/images/fcicons/hi_shwrs20.jpg
The last two digits are '20'
This should not:
http://www.nws.noaa.gov/weather/images/fcicons/skc.jpg
There are no last two digits
This should do the trick.
<?php
$filename = "http://www.nws.noaa.gov/weather/images/fcicons/skc23.jpg";
$posOfPeriod = strrpos($filename, ".");
$last2digits = substr($filename, $posOfPeriod -2, 2);
if (is_numeric($last2digits)) {
echo "Numeric: ".$last2digits;
}
else {
echo "Non-Numeric: ".$last2digits;
}
?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
$a='Would you like to have responses to your questions sent to you via email'
for($a as $b=>c){
}
Kindly give me the solution
<?php echo substr_count($a, 't'); ?>
Here's a solution, though not necessarily the best
$letterCount = array_count_values(
str_split(strtolower($a))
);
$tCount = (isset($letterCount['t'])) ? $letterCount['t'] : 0;
$count = preg_match_all('/t/', $str);
check this one
<?php
$a = 'Would you like to have responses to your questions sent to you via email';
$t_explod = explode('t', strtolower($a));
echo count($t_explod) - 1;
?>