我知道這是一個老問題,但我偶然發現了這個帖子尋找創建使用CSS超鏈接的解決方案,並最終使我自己,可能是跨越了這個問題的人磕磕絆絆,像我一樣的興趣:
這裏是調用的PHP函數 '連接器();',使假的CSS屬性
連接: 'url.com';
#id定義的項目。 只是讓PHP調用這個你認爲鏈接值得的每一項HTML。 輸入是.css文件作爲字符串,使用:
$ style_cont =的file_get_contents($ style_path);
和相應項目的#id。下面有整個事情:
function linker($style_cont, $id_html){
if (strpos($style_cont,'connect:') !== false) {
$url;
$id_final;
$id_outer = '#'.$id_html;
$id_loc = strpos($style_cont,$id_outer);
$connect_loc = strpos($style_cont,'connect:', $id_loc);
$next_single_quote = stripos($style_cont,"'", $connect_loc);
$next_double_quote = stripos($style_cont,'"', $connect_loc);
if($connect_loc < $next_single_quote)
{
$link_start = $next_single_quote +1;
$last_single_quote = stripos($style_cont, "'", $link_start);
$link_end = $last_single_quote;
$link_size = $link_end - $link_start;
$url = substr($style_cont, $link_start, $link_size);
}
else
{
$link_start = $next_double_quote +1;
$last_double_quote = stripos($style_cont, '"', $link_start);
$link_end = $last_double_quote;
$link_size = $link_end - $link_start;
$url = substr($style_cont, $link_start, $link_size); //link!
}
$connect_loc_rev = (strlen($style_cont) - $connect_loc) * -1;
$id_start = strrpos($style_cont, '#', $connect_loc_rev);
$id_end = strpos($style_cont,'{', $id_start);
$id_size = $id_end - $id_start;
$id_raw = substr($style_cont, $id_start, $id_size);
$id_clean = rtrim($id_raw); //id!
if (strpos($url,'http://') !== false)
{
$url_clean = $url;
}
else
{
$url_clean = 'http://'.$url;
};
if($id_clean[0] == '#')
{
$id_final = $id_clean;
if($id_outer == $id_final)
{
echo '<a href="';
echo $url_clean;
echo '" target="_blank">';
};
};
};
};
這也許可以提高/使用像.wrap()或的getElementById() 命令縮短,因爲它僅產生<a href='blah'>
部,但看到</a>
沒有開口子句無論如何消失它如果你只是將它們添加到其他地方,仍然有效:D
你是什麼意思自動?您需要在HTML上運行一些應用程序,將其轉換爲所需的結果。 – azamsharp 2008-10-02 23:48:54