duanping1920 2014-08-26 11:04
浏览 15

如何从不同的php模块组装php文件?

I'm pretty sure I just don't get the concept, but I'm stuck. The task: Assemble a php file from several php modules. Let's say we have a file1.php and a file2.php lying on a server. I now want to assemble those two files to a third php file, lets call it alltwo.php. This file (alltwo.php) will be offered as a download. I could do that quick an dirty by file_put_content, but as I understand it is no good idea to build php stuff on the fly, because it is too risky. All the example codes work with .txt files for a good reason I presume.

The most simple trick with include wont work, because I don't want the HTML output as a result but a genuine php file with the code from file1 and file2 in it. No changes, just one module after the other.

Tell me I'm stupid, thats okay. But maybe you can give me a hand.

  • 写回答

2条回答 默认 最新

  • dqeznd1697 2014-08-26 11:09
    关注

    This seems ugly, but I guess you have your reasons.

    If the files start with PHP tags that need removing I would use file:

    $fileA = file( 'fileA.php' );
    unset( $fileA[0] ); # remove opening tag
    unset( $fileA[count($fileA) - 1] ); #remove closing tag
    $conA = implode( "
    ", $fileA );
    

    Then do the same with the second file and concatenate.

    Otherwise just use file_get_contents and concat operator (.).

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数