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 8 years ago.
Improve this question
I have a variable inside an inline style -
style='color:$custom_color;font-size:$custom_icon_size;'
And am trying to add the letters px directly after the $custom_icon_size. This obviously does not work? Any ideas what is the correct method?
thanks
you need to use {} around your PHP vaariable
style='color:$custom_color;font-size:${custom_icon_size}px;'
Assuming that you're echoing it, you have two options:
echo "style='color:$custom_color;font-size:{$custom_icon_size}px;'";
echo "style='color:" . $custom_color . ";font-size:" . $custom_icon_size . "px;'";
$style = 'color:'.$custom_color.'; font-size: '.$custom_icon_size.'px';
echo 'style="'.$style.'"';
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 6 years ago.
Improve this question
I'm retrieving the postal code by using -
<?php $pstcde = file_get_contents('https://ipapi.co/'.$_SERVER['REMOTE_ADDR'] . '/postal/'); ?>
It works great but if the postal code is not found, it says, "None". I can't find a way to disable the message.
You can empty the variable if the respond is None. With a simple check.
<?php
$pstcde = file_get_contents('https://ipapi.co/'.$_SERVER['REMOTE_ADDR'] . '/postal/');
if($pstcde === "None")
$pstcde = ""; //Empty string. Or you can use unset($pstcde); if you want to unset the variable.
?>
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 6 years ago.
Improve this question
i want to echo a div in PHP, and set the ID equal to the value of $divName, but i cannot get it to work
Here is my code:
$divName = "divText"
echo '<div id=$divName></div>'
Just do it like this:
$divName = "divText";
echo '<div id="'.$divName.'"></div>';
You should read the PHP Documentation. This is really basic stuff.
http://php.net/docs.php
Why you don't add semicolons (;) at the end of each command line?
Change single quotes (') to double quotes (") and that it:
$divName = "divText";
echo "<div id=$divName></div>";
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
function wrap($str) {
$str="[#id=\"".$str."\"]";
return($str);
}
$str="Hi";
$str=wrap($str);
I would have $str like [#id="Hi"], but i have $str like [#id=\"Hi\"]
How could i do that?
$str='[#id="'.$str.'"]';
replace " with '
The code works as expected, no need to change quotes to single ticks or remove the second pair of double quotes.
Probably the backslashes are added later. If you just echo $str; after your snippet it shows this in a browser
[#id="Hi"]
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
Im newbie in php im learning it since some weeks ago but i didnt understand one thing.
I have a
$url = "http://example.com/";
define('LOCATION', '<?php echo $url; ?>');
but it is not working. I didnt understand why "define" term cannot read
<?php
$url = "http://example.com/";
define('LOCATION', $url);
1.You are alreay in php tag,so no need of any extra php tag.
2.And when assigning value to a variable , we never use echo in php . Its used to display value in html only.
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 8 years ago.
Improve this question
Please tell me how to do a find and replace in PHP.
I nee to find Entry="OK" and replace with OK in a xml file.
I tried str_replace but confused because of the = and " in it.
Even though I'm not sure of the environment you're working in, here's a php sample that I think does what you want:
<html>
<?php
$teststr = "Entry=\"OK\"";
print $teststr . "<br>";
$newanswer = str_replace($teststr, "Entry=OK", $teststr);
print $newanswer . "<br>";
?>
</html>
Try this way
str_replace('Entry="OK"','OK',$var);
You can use str_replace its working
$r = 'Entry="OK" tyyuu hhh';
echo str_replace($r,'Entry="OK"','OK');
if any error found then u use preg_replace with corresponding patteren