<ask>如何在其他页面中显示输出

时间:2015-12-01 06:12:47

标签: php

如何显示输出&#34; paragraf&amp;令牌&#34;在其他页面的PHP?我想展示参数&#34; paragraf&amp;令牌&#34;谢谢。

a.php

    function ringkasan($con, $isi){

    $paragraf = explode(". ", $isi);

    if(strlen($paragraf[count($paragraf)-1]) <= 1) {
        unset($paragraf[count($paragraf)-1]);
    }

    //1. Case Folding
    for($i=0; $i<count($paragraf); $i++){
        //Merubah ke huruf kecil
        $paragraf[$i] = strtolower($paragraf[$i]);
        //menghilangkan tanda baca
        // I wannat Display output this to other page =>  
        $paragraf[$i] = preg_replace("/[^A-Za-z0-9 ]/", "", $paragraf[$i]);
    }

    //4. Tokenizing
    $token = Array();
    foreach($paragraf as $item){
        $tmp = explode(" ", $item);

        foreach($tmp as $x){
            //I wannat Display output this to other page =>   
            $token[] = $x;
        }
    }

1 个答案:

答案 0 :(得分:0)

如果您的代码独立于内页面内容,则可以将其移动到其他文件(让我们称之为header.php)并将其包含在其他页面中:

[a.php/b.php/c.php]
require_once(__DIR__.'header.php');

// rest of code.

如果它确实有任何依赖关系并且您希望转移它而不是使用$_SESSION$_COOKIE

[a.php]
<?php
session_start();
// ...
$_SESSION['paragraph_name'] = preg_replace("/[^A-Za-z0-9 ]/", "", $paragraf[$i]);

[b.php]
<?php session_start(); ?>
<!-- ... -->
<section>
     <?php
     echo !empty($_SESSION['paragraph_name']) ? $_SESSION['paragraph_name'] : 'Default paragraph name';
     ?>
</section>