简体   繁体   English

我如何在以下代码的$ message语句中使用函数

[英]how can i use function in $message statement in the following code

suppose i have the following php code and i need to use the function named any_function in the string named $someotherthing , how can i use it, please help??? 假设我有以下php代码,并且我需要在名为$someotherthing的字符串中使用名为any_function的函数,我该如何使用它,请帮忙? and also can i use the string ( $something ) inside the function in $someotherthing ... 我也可以在$someotherthing函数中使用字符串( $something )...

<?php

function any_function(){
   $something = "something";
}

$someotherthing="need to use the above function here, how can i?";

?>

my actual code which i need to use is as follows, i need to use the visitor_country() function in $message 我需要使用的实际代码如下,我需要在$message使用visitor_country()函数

<?php
$fullName=$_REQUEST['fullName'];
$phnNumber=$_REQUEST['phnNumber'];
$enquery=$_REQUEST['enquery'];
$ipaddress = $_SERVER["REMOTE_ADDR"];
function visitor_country()
{
    $client  = @$_SERVER['HTTP_CLIENT_IP'];
    $forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
    $remote  = $_SERVER['REMOTE_ADDR'];
    $result  = "Unknown";
    if(filter_var($client, FILTER_VALIDATE_IP))
    {
        $ip = $client;
    }
    elseif(filter_var($forward, FILTER_VALIDATE_IP))
    {
        $ip = $forward;
    }
    else
    {
        $ip = $remote;
    }

    $ip_data = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=".$ip));

    if($ip_data && $ip_data->geoplugin_countryName != null)
    {
        $result = $ip_data->geoplugin_countryName;
    }

    return $result;
}

 $to="digibeem@gmail.com";
   $subject = "Contact Us form Details";
   $message = "\nFull Name : ".$fullName."\n Phone Number:".$phnNumber."\n General Enquiry : ".$enquery."\n IP Address : ".$ipaddress."\n Country: visitor_country() ";
   $from="dbedu@digibeem.com";
    @mail($to,$subject,$message,"From:$from");
    @header("location:../index.php");
?>

像其他变量一样添加即可:

$message = "\nFull Name : ".$fullName."\n Phone Number:".$phnNumber."\n General Enquiry : ".$enquery."\n IP Address : ".$ipaddress."\n Country: " . visitor_country();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM