Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I got this Error on my Page slider:
Warning: number_format() expects parameter 1 to be double, string given in /home/globalar/public_html/wp-content/themes/automotive_s1/includes/slider.php on line 30
<?php
if $str = floatval($str); ($post->post_type == "gtcd") {
the_title();
if (isset( $fields['price'])) {
echo ' | <span class="price_slider">'.' '.$symbols['currency'];
echo number_format($fields['price']).'</span> ';
} else {
echo '';
}
$fields['price']='8, 9858';
echo number_format((float)$fields['price']);
use (float) to parse correct way
You should check what value is inside $fields['price'].
Just do:
var_dump($fields['price']);
It's possible you have some spaces or , instead of .
fix it with define other variabel.
$tot=$row['total'];
$total=number_format($tot,2);
$tot2=$tot*1;
$vat=number_format($tot2*10/100,2);
maybe help
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Created app medium poster
http_build_query(): Parameter 1 expected to be Array or Object.
Code:
Error: in line 75
$url .= (strpos($url , '?') !== false ? '&' : '?') . http_build_query($data);
why? this error in my code, check please
make sure $data is an array or object. find the example below
$data = ['id'=>25, 'name'=>'test']; //array
$url = "http://google.com";
$url .= (strpos($url , '?') !== false ? '&' : '?') . http_build_query($data);
echo $url;
//Output: http://google.com?id=25&name=test
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
$defaultdata = "abcdef00000000000000000000000000";
$data1 = "271";
$output = "abcdef00000000000000000000000271";
How can I replace the string based on the data. For example, if the default data is abcdef00000000000000000000000000 , so it will replace when the data1 got value. So the output will be abcdef00000000000000000000000271. How can I do this?
I'd use substr:
$output = substr($defaultdata,0,strlen($defaultdata)-strlen($data1)) . $data1;
Applying it to your code
<?php
$defaultdata = "abcdef00000000000000000000000000";
$data1 = "271";
$output = substr($defaultdata,0,strlen($defaultdata)-strlen($data1)) . $data1;
echo $output;
?>
$output = substr($defaultdata, 0, strlen($defaultdata) - strlen($data1));
$output .= $data1
I think the easiest way to solve this is to use str_pad. It is a built in function made to tackle situations like yours. Then you can easly swap defaultdata to something other. The code is as follow:
$output = str_pad($data1, strlen($defaultdata), $defaultdata, STR_PAD_LEFT);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Hi guys i'm having a small issue when i try and convert my exisiting script into a simple function. I'll leave my code below.
PHP:
function service_check($postcode) {
$op_postcodes = array(... "DG10","DG3","DG4" ...);
if(isset(htmlentities($postcode))) {
$postcode_checker = trim(strtoupper(htmlentities($postcode)));
$trim_postcode = trim(substr(htmlentities($postcode_checker, 0, -3)));
if(empty($postcode_checker)) {
$error = "We require your postcode to check our service in your area.";
} else if(!valid_postcode($postcode_checker)) {
$otp = "The postcode you entered is invalid.";
} else if(!in_array($trim_postcode, $op_postcodes)) {
$otp = "Sorry, but we don't provide our service's in your area, just yet.";
} else {
$otp = "Great news! We're in your area and you are eligible to order our services!";
$_SESSION['customer_postcode'] = $postcode_checker;
}
} else {
$otp = "To get started please enter your postcode.";
}
}
My current usage of the function is <?php service_check($_POST['service_check']); ?>
My error is:
Fatal error: Cannot use isset() on the result of a function call (you can use "null !== func()" instead) in /home/domain.com/public_html/controller/application/functions/locale.SM.php on line 27
change this
if(isset(htmlentities($postcode))) {
to this
$pc = htmlentities($postcode);
if(isset($pc)) {
read this if you get sometime - http://php.net/manual/en/function.isset.php http://php.net/manual/en/function.htmlentities.php
Since your questions wasn't complete i assume so now an edit. The better approach could be to use !empty() instead of isset() on our if condition.
Even better, reove htmlentities method call from your if block and then later use html entities when you actually need it.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I am trying to convert centimeters into feets and inches using PHP.
This is function I use for this calculation.
function getMeasurements($cm) {
$inches = ceil($cm/2.54);
$feet = floor(($inches/12));
$measurement = $feet."' ".($inches%12).'"';
return $measurement;
}
I am calling this function like this :
$cm = 185;
echo "My Height = ".getMeasurements($cm);
Problem is after calling this I can get a result like this-
My Height = 6' 73"
look at inches. Its incorrect. can anybody tell me whats the reason to get such a result.
Thank you.
[akshay#localhost tmp]$ cat test.php
<?php
function cm2feet($cm)
{
$inches = $cm/2.54;
$feet = intval($inches/12);
$inches = $inches%12;
return sprintf('%d ft %d ins', $feet, $inches);
}
echo cm2feet(162)
?>
Output
[akshay#localhost tmp]$ php test.php
5 ft 3 ins
The reason this is happening is that when you run it on phpfiddle.org it is not a true PHP environment. To fix this on phpfiddle, you should add space around your modulus operator.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
My Php mysql out put is array i need if string contain particular character i need print that string only
while($row2 = mysqli_fetch_array($result2)) {
echo $row2['link'];
}
Output is:
http://www.videoweed.es/file/b38300afda3e6
http://www.novamov.com/video/303a4428f6c6a
http://www.movshare.net/video/081aaa1356a6b
i need like this
if (strpos($a,'videoweed') !== false) {
echo $row2['link'];
}
it show out put is:
http://www.videoweed.es/file/b38300afda3e6
http://www.novamov.com/video/303a4428f6c6a
http://www.movshare.net/video/081aaa1356a6b
I need output only;
http://www.videoweed.es/file/b38300afda3e6
You have answer in your code. Just need to assemble it. check this:-
while($row2 = mysqli_fetch_array($result2)) {
if (strpos($row2['link'],'videoweed') !== false) {
echo $row2['link'];
}
}