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
For example
I'm looking for a function that keeps incrementing letters
Starts wit "aaaaaa" and goes to "aaaaab" and ends with "zzzzzz"
Use PHP's ability to increment characters Perl style
$char = 'aaaaaa';
$endChar = 'zzzzzz';
$endChar++;
while ($char != $endChar) {
echo $char++, PHP_EOL;
}
Just use increment operator
$start = "aaaaaa";
$end = "zzzzzz";
while($start ++ != $end) {
// print after every 10,000,000 million
(#$i ++ % 10000000 == 0) and print($start . PHP_EOL);
}
echo "Total ", number_format($i, 0);
Output
aaaaab
avwyxl
brtxuv
cnqwsf
djnvpp
efkumz
fbhtkj
fxesht
gtbrfd
hoyqcn
ikvozx
jgsnxh
kcpmur
kymlsb
lujkpl
mqgjmv
nmdikf
oiahhp
pdxgez
pzufcj
qvrdzt
rrocxd
snlbun
tjiarx
ufezph
vbbymr
vwyxkb
wsvwhl
xosvev
ykpucf
zgmszp
Total 308,915,775
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
How can I format a string to prepend UTC if it starts with + or - and add a : before the last two digits if it ends with 4 digits?
Examples and expected result:
PST > PST
+08 > UTC+08
-0845 > UTC-08:45
Thank you!
<?php
$string = "PST";
if (substr($string, 0, 1) === '+' || substr($string, 0, 1) === '-'){
if(strlen($string) == 3){
$newString = 'UTC'.$string;
}
else{
$newString = 'UTC'. substr($string, 0, 3). ':' .substr($string, -2, 2);
}
}
else{
$newString = $string;
}
echo $newString;
You don't need regex for that or at least regex seems overkill. You can simple create this logic using an if-else and modify your string accordingly
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I would like to create a website that allows a user to generate a selectable number of unique strings of text that all follow an algorithm but as it is website based I am not too sure about how I go about it.
For example user A wants to generate 20 strings of unique text that all follow say AA***B^^** where A&B is a constant that doesn't change, where * is a random number and ^ is a random letter.
Is that possible? I am thinking of using php rand for the number but not 100% sure.
Thanks
You could use something like this:
<?php
function randomGenerator($string)
{
$string_array = str_split( $string );
$characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
foreach ($string_array as $k => $v) {
if ($v == '*')
$string_array[$k] = rand(0,9);
if ($v == '^')
$string_array[$k] = $characters[rand(0,51)];
}
$string = implode('', $string_array);
return $string;
}
echo randomGenerator('AA***NN^^'); // may print AA478NNhU
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 a variable as $x=some_float_value. So how can I validate or check that $x is a Positive Float.
For Ex.
$x=-4.99;
function checkFloat($x){
/////return true if it is Positive
}
Please Tell me how can i do this.
Use filter_var() with FILTER_VALIDATE_FLOAT:
if (filter_var($x, FILTER_VALIDATE_FLOAT) && $x > 0) {
// ok
}
See it in action
Check if it is a float with is_float and > 0:
function checkFloat($x) {
return (is_float($x) && $x > 0);
}
I do not see the issue...
return $x > 0;
To conclude:
function checkPositive($x) {
return $x > 0;
}
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
Looking for the correct way to code the Weight Watcher PointsPlus formulas for "Food Values" and "Food with Alcohol and Sugar Alcohol" into Ruby and/or PHP.
Here is the link to the formula: http://en.wikipedia.org/wiki/Weight_Watchers#Formulas
Thanks in advance for the help!
Update:
As per the help from #mjayt below, I have the code below. My goal is to learn how to properly think, organize and solve formulas through code. I believe help correctly solving the two formulas will greatly help. Thanks again.
$protein = 8;
$carbs = 30;
$fat = 12;
$fiber = 8;
$pointsplus = round((($protein * 16) + ($carbs * 19) + ($fat * 45) - ($fiber * 14)) / 175, 0);
echo $pointsplus;
Okay, so I was bored... here is the first one. This should get you going
$protein = 8;
$carbs = 30;
$fat = 12;
$fiber = 8;
$pointsplus = round((($protein * 16) + ($carbs * 19) + ($fat * 45) - ($fiber * 14)) / 175, 0);
echo $pointsplus;
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
For example I have this range:
20 to 200
How can I programmatically get the value for a specific percentage, lets say 40% between those 2 numbers?
Simple example:
0 to 200
I want to get the value of 40%. Answer is 80.
Try this:
function percentage_from_range($from, $to, $percentage) {
$result = (($to - $from) / 100 * $percentage) + $from;
return $result;
}
e.g.
echo percentage_from_range(20, 200, 40); //92
$num1=20;
$num2=200;
$percent=40;
$total=$num2-$num1;
$result = (($total/100) * $percent)+$num1;
$lwb = 20;
$upb = 200;
$perc = 40;
$value = $lwb + ($upb - $lwb) * $perc / 100;
Takes perc/100 part of range, and start with the lowerbound.