0
我正在使用TinySong api來生成一個鏈接,它的工作原理,現在我嘗試使用它的鏈接。它沒有。我不知道爲什麼它不是linkifing我相信我使用了正確的變量。這是代碼。Linkify PHP文本
<?php
// linkify URLs
$pre = preg_replace(
'/(https?:\/\/\S+)/',
'<a href="\1">\1</a>',
$pre
);
?>
<script src="http://platform.twitter.com/anywhere.js?id= MY API KEY&v=1" type="text/javascript"></script>
<?php
class Tinysong
{
protected $api_key = '';
protected $method = '';
protected $limit = '';
protected $query_string = '';
public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
CURLOPT_USERAGENT => 'tinysong-php-0.7',
);
public function __construct($api_key)
{
$this->api_key = $api_key;
}
/**
* A wrapper for RESTful method /a/ (single
* @return @Tinysong
*/
public function single_tinysong_link($query_string)
{
$this->query_string($query_string);
return $this->method('a');
}
public function search($query_string)
{
$this->query_string($query_string);
return $this->method('a');
}
/**
* A wrapper for RESTful method /s/ (search)
* @return Tinysong
*/
/**
* Sets the query string
* @return Tinysong
*/
public function query_string($query_string)
{
$this->query_string = urlencode($query_string);
return $this;
}
/**
*
* @param type $method
* @return Tinysong
*/
public function method($method)
{
$this->method = $method;
return $this;
}
/**
* Fetchs the data based on the parameters
* @param bool $clean_params cleans the params after build the url
* @param resource $ch a custom php curl resource
* @return array an associative array with the data
*/
public function execute($clean_params = true, $ch = null)
{
$url = $this->build_query();
if ($clean_params)
{
$this->clean_params();
}
if (!$ch)
{
$ch = curl_init($url);
curl_setopt_array($ch, self::$CURL_OPTS);
}
$query_result = curl_exec($ch);
curl_close($ch);
return json_decode($query_result, true);
}
/**
* Builds an API query based on the parameters
* @return string the query
*/
public function build_query()
{
$url = "http://tinysong.com";
$url .= '/'.$this->method.'/';
$url .= $this->query_string.'?';
if ($this->limit)
{
$url .= 'limit='.$this->limit;
}
$url .= '&key='.$this->api_key;
$url .= '&format=json';
return $url;
}
/**
* Cleans the params (method, query string and limit)
* @return Tinysong
*/
public function clean_params()
{
$this->method = '';
$this->query_string = '';
$this->limit = '';
}
}
?>
如何使結果鏈接可點擊?我甚至使用正確的代碼?由於
你更可能,如果你在你的代碼,而不是傾銷數額是多少,整個腳本到一個代碼塊隔離特定問題領域得到積極的幫助。就我個人而言,我沒有願意或傾向於逐行篩選代碼來尋找潛在的問題。做一些預調試以找出沒有明確工作的東西並詢問有關情況。 – rdlowrey 2012-02-12 16:39:10