随机显示2个META标签

时间:2017-06-15 12:00:09

标签: php

我想在像...这样的页面中显示元标记。

<meta property="og:title" content="Hi Admin, How are you" />
<meta property="og:image" content="http://example.com/hiadmin.jpg" />

<meta property="og:title" content="Hi User, How are you" />
<meta property="og:image" content="http://example.com/user.jpg" />

问题 -

我想随机显示元标记,如..

你好管理员,你好吗(10次中有9次) 嗨用户,你好吗(10次中有1次)

我该怎么做?完全糊涂了:/

1 个答案:

答案 0 :(得分:1)

您正在寻找的是:

<?php
if (rand(1, 10) == 1){
?>
<meta property="og:title" content="Hi User, How are you" />
<meta property="og:image" content="http://example.com/user.jpg" />
<?php
} else {?>
<meta property="og:title" content="Hi Admin, How are you" />
<meta property="og:image" content="http://example.com/hiadmin.jpg" />
<?php }?>