例如,我有一个文本文件1.txt
,其内容如下
<span id="1" class="locations_div">
<select name="loc_lev_one" id="loc_lev_one" class="location" >
<option value="blank">Select</option>
<option value="1">London</option>
<option value="2">Bristol</option>
</select>
</span>
我包括文本文件include('1.txt');
结果见html选择框。
但希望看到部分选择框代码(作为字符串)。
尝试echo substr( ( include('1.txt') ), 10 );
但请参见相同的/初始选择弓。
如何获取文本文件的部分代码?
尝试
echo substr( ( file_get_contents( '1.txt' ) ), 100 );
,并视为字符串。
因此,在这种情况下,不需要include
,只需要使用file_get_contents
您可以这样使用include()
:
ob_start();
?>
include "1.txt";
<?php
$str = ob_get_clean();
echo(substr($str, 10));
但函数file_get_contents()
要好得多。