• php知识点总结(一)


     

    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);

    ?>

  • 相关阅读:
    java快速排序代码
    java操作redis实现和mysql数据库的交互
    python 操作mysql数据库存
    JAVA 操作远程mysql数据库实现单表增删改查操作
    URI和URL及URN的区别
    day06_字符集设置
    day6_oracle手工建库
    day08_SGA后半部分
    day08_存储
    day05_sqlloader基础
  • 原文地址:https://www.cnblogs.com/iriliguo/p/php.html
Copyright © 2020-2023  润新知