I have the following code;
<?php
function countryCityFromIP($ipAddr)
{
$url = "http://api.ipinfodb.com/v3/ip-city/?key=5cfaab6c5af420b7b0f88d289571b990763e37b66761b2f053246f9db07ca913&ip=$ipAddr&format=json";
$d = file_get_contents($url);
return json_decode($d , true);
}
if (isset($_REQUEST['submit']))
{
$ip = countryCityFromIP($_REQUEST['ip']);
//print_r($ip);
echo $ip['cityName'];
echo $ip['countryName'];
}
?>
<form method="post">
<input type="text" name="ip" />
<input type="submit" name="submit" value="Find" />
</form>
I need to style "echo $ip['cityName']" here. I tried a lot methods, but I am only getting an error.
You can style it by the following way:
echo "<p style='color:red;'>" . $ip['cityName'] . "</p>";
echo "<p style='color:red;'>" . $ip['countryName'] . "</p>";
Echo inside an HTML element with class
and style the element:
echo "<span class='name'>" . $ip['cityName'] . "</span>";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With