简体   繁体   English

文档名称(将 php 转换为?)

[英]Document Name (conversion php to ?)

Hi I am currently using php to add the document name so example.嗨,我目前正在使用 php 添加文档名称,例如。

folder/<?phpecho basename(__FILE__, '.' . pathinfo(__FILE__,
PATHINFO_EXTENSION));?>_button.png 

What i have noticed is that by using php to do this and having multiple examples of this it is dramatically increasing my page load time.我注意到的是,通过使用 php 来执行此操作并有多个示例,这大大增加了我的页面加载时间。 What i wish is for a similar method using client side scripting.我希望的是使用客户端脚本的类似方法。

If you are truly convinced that this is slowing your page times down, then you need to prove it.如果您真的确信这会减慢您的页面时间,那么您需要证明这一点。 Use the microtime() function to test each function call and see what's actually slowing things down.使用microtime() function 来测试每个 function 调用,看看是什么真正减慢了速度。 For example:例如:

<?php
    $t0 = microtime(TRUE);
    $ext = pathinfo(__FILE__, PATHINFO_EXTENSION);
    $t1 = microtime(TRUE);
    $filename = basename(__FILE__, '.' . $ext);
    $t2 = microtime(TRUE);

    echo "pathinfo() took " . $t1-$t0 . " seconds.  ";
    echo "basename() took " . $t2-$t1 . " seconds.  ";
    echo "total time: " . $t2-$t0 " . " seconds.";
?>

And if you determine that it is taking too long, find a better way to do it.如果您确定它花费的时间太长,请找到更好的方法来完成它。 Or, at least save this calculated value to a variable and echo that throughout the multiple places you need it.或者,至少将此计算值保存到一个变量中,并在您需要它的多个地方进行回显。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM