当前位置:  编程技术>php
本页文章导读:
    ▪php与css 标签云效果      以下代码,实现一个标签云的效果。 只给出核心代码,供大家学习参考。 1,创建标签云的函数   代码示例: function createTagCloud($tags)  {         //I pass through an array of tags      $i=0;.........
    ▪分享二个php 标签云的实例代码      1,php标签云的效果示例一 代码示例: <?php //标签云效果 function printTagCloud($tags) {  // $tags is the array  arsort($tags);  $max_size = 32; // max font size in pixels  $min_size = 12; // min font size in pixels  // la.........
    ▪php正则验证email地址的例子      以下分享的这段简单代码,借助php的正则表达式来验证email地址的有效性。 有兴趣的朋友,可以研究下。 代码: <html> <head> <title>php正则验证email地址-www.</title> </head>.........

[1]php与css 标签云效果
    来源: 互联网  发布时间: 2013-12-24

以下代码,实现一个标签云的效果。
只给出核心代码,供大家学习参考。

1,创建标签云的函数
 

代码示例:
function createTagCloud($tags) 
{    
    //I pass through an array of tags 
    $i=0; 
    foreach($tags as $tag) 
    { 
        $id = $tag['id']; //the tag id, passed through 
        $name = $tag['tag']; //the tag name, also passed through in the array 
         
        //using the mysql count command to sum up the tutorials tagged with that id 
        $sql = "SELECT COUNT(*) AS totalnum FROM tutorials WHERE tags LIKE '%".$id."%' AND published = 1"; 
         
        //create the resultset and return it 
        $res = mysql_query($sql); 
        $res = mysql_fetch_assoc($res); 
         
        //check there are results ;) 
        if($res) 
        { 
            //build an output array, with the tag-name and the number of results 
            $output[$i]['tag'] = $name;  
            $output[$i]['num'] = $res['totalnum']; 
        } 
         
        $i++; 
    } 
     
    /*this is just calling another function that does a similar SQL statement, but returns how many pieces of content I have*/ 
    $total_tuts = $this->getNumberOfTutorials(); 
     
    //ugh, XHTML in PHP?  Slap my hands - this isn't best practice, but I was obviously feeling lazy 
    $html = '<ul >'; 
     
    //iterate through each item in the $output array (created above) 
    foreach($output as $tag) 
    { 
        //get the number-of-tag-occurances as a percentage of the overall number 
        $ratio = (100 / $total_tuts) * $tag['num']; 
         
        //round the number to the nearest 10 
        $ratio =  round($ratio,-1); 
         
        /*append that classname onto the list-item, so if the result was 20%, it comes out as cloud-20*/ 
        $html.= '<li .$ratio.'"><a href="/tag/index.html'.$tag['tag'].'">'.$tag['tag'].'</a></li>';          
    } 
     
    //close the UL 
    $html.= '</ul>'; 
     
    return $html;  

2,css代码部分
/*删除默认的列表样式,使之成为一个普通的清单列表*/ 
 

代码示例:
.home-item ul.tagcloud 

    list-style-type:none; 
    margin:0px; 
    padding:0px; 

 
/*设置li的样式*/ 
.home-item ul.tagcloud li 

    display:inline !important; 
    margin-right:15px; 
    line-height:2em; 

 
.home-item ul.tagcloud li a 

    display:inline; 

 
/*标签云的效果*/ 
.home-item ul.tagcloud li.cloud-10 a 

    font-size:110%; 

 
.home-item ul.tagcloud li.cloud-20 a 

    font-size:120%; 

 
.home-item ul.tagcloud li.cloud-30 a 

    font-size:130%; 

 
/************************************* 
you get the idea, i'm skipping a few 
*************************************/ 
 
.home-item ul.tagcloud li.cloud-90 a 

    font-size:190%; 

 
.home-item ul.tagcloud li.cloud-100 a 

    font-size:200%; 

    
[2]分享二个php 标签云的实例代码
    来源: 互联网  发布时间: 2013-12-24

1,php标签云的效果示例一

代码示例:

<?php
//标签云效果
function printTagCloud($tags) {
 // $tags is the array

 arsort($tags);

 $max_size = 32; // max font size in pixels
 $min_size = 12; // min font size in pixels

 // largest and smallest array values
 $max_qty = max(array_values($tags));
 $min_qty = min(array_values($tags));

 // find the range of values
 $spread = $max_qty - $min_qty;
 if ($spread == 0) { // we don't want to divide by zero
  $spread = 1;
 }

 // set the font-size increment
 $step = ($max_size - $min_size) / ($spread);

 // loop through the tag array
 foreach ($tags as $key => $value) {
  // calculate font-size
  // find the $value in excess of $min_qty
  // multiply by the font-size increment ($size)
  // and add the $min_size set above
  $size = round($min_size + (($value - $min_qty) * $step));

  echo '<a href="#" . $size . 'px"
title="' . $value . ' things tagged with ' . $key . '">' . $key . '</a> ';
 }
}

$tags = array('weddings' => 32, 'birthdays' => 41, 'landscapes' => 62,
'ham' => 51, 'chicken' => 23, 'food' => 91, 'turkey' => 47, 'windows' => 82, 'apple' => 27);

printTagCloud($tags);
?>

2,php标签云的效果示例二

代码示例:

<style type="text/css">
.tag_cloud { padding: 3px; text-decoration: none; }
.tag_cloud:link  { color: #81d601; }
.tag_cloud:visited { color: #019c05; }
.tag_cloud:hover { color: #ffffff; background: #69da03; }
.tag_cloud:active { color: #ffffff; background: #ACFC65; }
</style>
function get_tag_data() {
    $arr = Array('Actionscript' => 35, 'Adobe' => 22, 'Array' => 44, 'Background' => 43,
 'Blur' => 18, 'Canvas' => 33, 'Class' => 15, 'Color Palette' => 11, 'Crop' => 42,
 'Delimiter' => 13, 'Depth' => 34, 'Design' => 8, 'Encode' => 12, 'Encryption' => 30,
 'Extract' => 28, 'Filters' => 42, 'Flash' => 32, 'Functions' => 19,
 'Gaussian Blur' => 44, 'Grafix' => 49, 'Graphics' => 35, 'Hue' => 47, 'Illustrator' => 8,
 'Image Ready' => 12, 'Javascript' => 47, 'Jpeg' => 15,  'Keyboard' => 18, 'Level' => 28,
 'Liquify' => 30, 'Listener' => 10, 'Logo' => 12, 'Loops' => 22, 'Macromedia' => 26,
 'Method' => 28, 'MySQL' => 18, 'Obfuscation' => 13, 'Object' => 39, 'Optimize' => 25,
 'PDF' => 37, 'PHP' => 44, 'PSD' => 17, 'Photography' => 28, 'Photoshop' => 46,
 'Revert' => 50, 'Saturation' => 35, 'Save as' => 28, 'Scope' => 11, 'Scripting' => 9,
 'Security' => 41, 'Sharpen' => 49, 'Switch' => 41, 'Templates' => 11, 'Texture' => 22,
 'Tool Palette' => 30, 'Variables' => 50);
    return $arr;

function get_tag_cloud() {
// Default font sizes
$min_font_size = 12;
$max_font_size = 30;

// Pull in tag data
$tags = get_tag_data();

//构造标签云的html代码
$cloud_html = '';
$cloud_tags = array(); // create an array to hold tag code
foreach ($tags as $tag => $count) {
 $size = $min_font_size + ($count - $minimum_count)
  * ($max_font_size - $min_font_size) / $spread;
 $cloud_tags[] = '<a . floor($size) . 'px'
  . '" href="http://www.google.com/search?q=' . $tag
  . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">'
  . htmlspecialchars(stripslashes($tag)) . '</a>';
}
$cloud_html = join("\n", $cloud_tags) . "\n";
return $cloud_html;
}
Usage:
<h3>php标签云效果</h3>
<div id="wrapper"
<!-- BEGIN Tag Cloud -->
<?php print get_tag_cloud(); ?>
<!-- END Tag Cloud -->
</div>

说明:
如果需要使用mysql数据库来存储与获取标签信息,请将以上函数,替换上面的函数get_tag_data()即可:

代码示例:
function get_tag_data() {
  mysql_connect('localhost', 'username', 'password');
  mysql_select_db('database');
  $result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY count DESC");
  while($row = mysql_fetch_array($result)) {
    $arr[$row['tag']] = $row['count '];
  }
  ksort($arr);
  return $arr;
}

    
[3]php正则验证email地址的例子
    来源: 互联网  发布时间: 2013-12-24

以下分享的这段简单代码,借助php的正则表达式来验证email地址的有效性。
有兴趣的朋友,可以研究下。

代码:

<html>
<head>
<title>php正则验证email地址-www.</title>
</head>
<body>
<?php
/**
* 检测输入的email地址是否有效
* by www.
*/
if (isset($_POST['posted'])) {
   $email = $_POST['email'];
   $theresults = ereg("^[^@ ]+@[^@ ]+.[^@ .]+$", $email, $trashed);
   if ($theresults) {
      $isamatch = "有效的email地址";
   } else {
      $isamatch = "无效的email地址";
   }

   echo "经验证,您输入的Email:是" . $isamatch;
}

?>
<form action="/blog_article/</php echo $_SERVER[.html'PHP_SELF']; ?>" method="POST">
<input type="hidden" name="posted" value="true">
请输入要验证的E-Mail地址:
<input type="text" name="email" value="name@example.com">
<input type="submit" value="Validate">
</form>
</body>
</html>

    
最新技术文章:
▪PHP函数microtime()时间戳的定义与用法
▪PHP单一入口之apache配置内容
▪PHP数组排序方法总结(收藏)
▪php数组排序方法大全(脚本学堂整理奉献)
▪php数组排序的几个函数(附实例)
▪php二维数组排序(实例)
▪php根据键值对二维数组排序的小例子
▪php验证码(附截图)
▪php数组长度的获取方法(三个实例)
▪php获取数组长度的方法举例
▪判断php数组维度(php数组长度)的方法
▪php获取图片的exif信息的示例代码
▪PHP 数组key长度对性能的影响实例分析
▪php函数指定默认值的方法示例
▪php提交表单到当前页面、提交表单后页面重定...
▪php四舍五入的三种实现方法
▪php获得数组长度(元素个数)的方法
▪php日期函数的简单示例代码
▪php数学函数的简单示例代码
▪php字符串函数的简单示例代码
▪php文件下载代码(多浏览器兼容、支持中文文...
▪php实现文件下载、支持中文文件名的示例代码...
▪php文件下载(防止中文文件名乱码)的示例代码
▪解决PHP文件下载时中文文件名乱码的问题
▪php数组去重(一维、二维数组去重)的简单示例
▪php小数点后取两位的三种实现方法
▪php Redis 队列服务的简单示例
▪PHP导出excel时数字变为科学计数的解决方法
▪PHP数组根据值获取Key的简单示例
▪php数组去重的函数代码示例
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3