<;询问>;如何在其他页面中显示输出


<ask> How to display output in other page

如何在其他页面php中显示输出"paragraf&token"?我想显示参数"paragraf&token"之前谢谢。

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

如果您的代码独立于内部页面内容,则可以将其移动到其他文件(称为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>