我知道这是一个老问题,但我偶然发现了这个帖子寻找创建使用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