我有兩個獨立於單獨的php頁面獨立工作的PHP函數。將2個現有的php函數合併爲一個
第一頁:
<?php
function shortURL($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$short_url = curl_exec($ch);
curl_close($ch);
return $short_url;
}
$url = "http://technoflirt.com/tech/2011/01/11/running-php-script-host/";
$short_url = shortURL($url);
echo "Actual url =". $url . "<br />";
echo "Shortened url = <a href=$short_url>$short_url</a> <br />";
?>
頁二是現有的片段,電子郵件信息。我嘗試將功能與沒有運氣的功能結合起來,在函數email()上面粘貼shortURL($ url)函數,然後粘貼$ url和$ short_url,並將echo語句更改爲$ message。這導致了一個致命錯誤:PHP致命錯誤:調用未定義的函數shortURL(),所以我知道這是行不通的。如何成功轉換tinyURL,然後將其合併到函數電子郵件中?
function shortURL($url) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,'http://tinyurl.com/api-create.php?url='.$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$short_url = curl_exec($ch);
curl_close($ch);
return $short_url;
function email($array, $task, $techinfo,$additionalinfo = array()) {
$to = $techinfo["EmpHTEmail"];
$url = "http://technoflirt.com/tech/2011/01/11/running-php-script-host/";
$short_url = shortURL($url);
$subject = ($task == "unschedule") ? '' : ($task == "notify" ? "": "Else Message");
$message = "";
if($task == "unschedule")
$message .="Work Order #:" . $array[0]["WorkOrderNum"] . " is cancelled.";
elseif($task == "notify")
{
$message .="".$additionalinfo[0]['sShortName']." (" . $array[0]["WorkOrderNum"] . ") <BR>".$additionalinfo[0]['sAddressNum']." ".$additionalinfo[0]['sAddressLine1'].", ".$additionalinfo[0]['sCityName']."<BR>".$additionalinfo[0]['sPhone1'] . " - ".$_SESSION['Latitude'].",".$_SESSION['Longitude']."<BR>";
$message .="". $additionalinfo[0]['JobDescription'] . " - ". $url . "";
$message .="Actual url =". $url . "";
$message .="Shortened url = $short_url";
}
$message .="";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($to, $subject, $message, $headers);
}
我確實......我更新了第二個代碼塊......這是我合併這兩個文件的過程,它給了我一個問題。 –