autoload函数中的trim和str_replace有什么作用?

时间:2017-03-08 04:43:25

标签: php

我正在研究自动加载。我找到了这行代码,其中trim和str_replace做同样的事情,摆脱了反斜杠(在我的未知中)。

但我不明白为什么他们需要这样做?

有人可以解释一下吗?

var sphere = new THREE.SphereGeometry(200, 100, 100);

//Skipping unrelated code and to include creating sphere mesh and adding it to the scene

var curve = new THREE.QuadraticBezierCurve3(
	new THREE.Vector3(xStart, yStart, zStart),
  new THREE.Vector3((xStart+xEnd)/2 + xOffset, (yStart+yEnd)/2 + yOffset, (zStart+zEnd)/2 + zOffset), //Midpoint with offset
	new THREE.Vector3(xEnd, yEnd, zEnd)
);

var geometry = new THREE.Geometry();
geometry.vertices = curve.getPoints( 50 );

var line = new THREE.Line(geometry, materialLine);
globe.scene.add(line);

1 个答案:

答案 0 :(得分:0)

trim删除字符串开头的反斜杠 然后str_replace用常量DIRECTORY_SEPARATOR替换所有其他反斜杠。

为了论证,我们说DIRECTORY SEPARATOR/

$class = '\One\Ting\ming'; \\ notice that I have added a leading backslash

strtolower(str_replace("\\", DIRECTORY_SEPARATOR, trim($class, "\\"))).".php";

修剪前导反斜杠后,变为

strtolower(str_replace("\\", DIRECTORY_SEPARATOR, "One\Ting\ming")).".php";

然后将所有\更改为/,它变为

strtolower("One/Ting/ming").".php";

最后,将字符串更改为全部小写并附加文件扩展名,它变为

"one/ting/ming.php";