php知识点总结(一)

本文介绍如何用PHP将多维数组以表格形式展示,并演示了如何利用str_ireplace()函数对字符串中的特定词汇进行高亮显示,包括替换颜色和加粗效果。

 

1.把数组以表格的形式显示

<?php

$array = array(

  '书籍' =>  array( '生活',  '人与自然','动物世界'),

    '体育用品' =>  array( '乒乓球','网球','高尔夫球'),

      '水果' => array( '橙子',  '葡萄','苹果')

);

//创建表格将数组循环输入

    echo '<table border="1" width="600" align="center" >';

    echo '<tr bgcolor="#dddddd">';

    echo '<th>name1</th><th>name2</th><th>name3</th>';

    echo '</tr>';

    foreach ($array as $value)

    {

        echo '<tr>';

//foreach里面嵌套一个for循环也是可以的

        /*for($n=0;$n<count($value);$n++)

        {

            echo "<td>$value[$n]</td>";

        }*/

//foreach里面嵌套foreach

 

        foreach($value as $mn)

        {

            echo "<td>$mn</td>";

        }

        echo '</tr>';

    }

    echo '</table>';

?>

 

2.使用str_ireplace()函数替换查询关键字,当显示所查询的相关信息时,将输出的关键字的字体替换为红色

<?php

$content="白领女子公寓,温馨街南行200米,交通便利,亲情化专人管理,您的理想选择!";

$str="女子公寓";

echo str_ireplace("白领女子公寓","<font color=red>$str</font>",$content);

?>

 

3. 对检索到的用户输入的查询关键字进行加粗描红

 

<html>

<head>

<title> </title>

</head>

<body>

<form id="form1" name="form1" method="post" action="php_03.php">

<input type="text" name="txt" />

<input type="submit" name="ss" value="提交" />

<div><br />

The breakout sci-fi drama took a couple years to make it to air, so it’s perhaps not surprising it will take awhile for another round. The densely plotted, special-effects-filled series is labor intensive, and showrunner Jonathan Nolan and Lisa Joy want to have all 10 episodes written before starting filming. So we’re going to have to wait awhile before we find out what “SW” is all about.

</div>

</form>

</body>

</html>

<?php

error_reporting(0);// 关闭错误报告

 

$txt=$_POST["txt"];

 

$bt=$_POST["ss"];

$wz="

The breakout sci-fi drama took a couple years to make it to air, so it’s perhaps not surprising it will take awhile for another round. The densely plotted, special-effects-filled series is labor intensive, and showrunner Jonathan Nolan and Lisa Joy want to have all 10 episodes written before starting filming. So we’re going to have to wait awhile before we find out what “SW” is all about.

";

echo "<br />";

echo str_ireplace($txt,"<b style='color:FF0000'>".$txt."</b>",$wz);

?>

转载于:https://www.cnblogs.com/iriliguo/p/php.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值