帮助列表输出
我这里有这个表达式,
$data = file_get_contents('groups.txt');
function links1($l1, $l2){echo "<a href='". $l1 ."'><img src='". $l2 ."'/></a>";}
$parsed1 = get_string_between($data, "[Group1]", "[/Group1]");
$data = explode("\n", $parsed1);
foreach($data as $string2){
list($l1, $l2) = explode(' ', $string2);
links1($l1, $l2);}}
我有一个 get_string_ Between 定义为上面的函数,它获取“[Group1]”和“[/Group1]”之间的任何内容。 文本文件组包含内容:
[Group1]
aaa 1.png
bbb 2.jpg
[/Group1]
问题是,当我运行它时,它输出为
<a href=''><img src=''/></a><a href='aaa'><img src='1.png'/></a><a href='bbb'><img src='2.jpg'/></a><a href=''><img src=''/></a>
所以我得到这些虚拟的两个空格,我猜它们被添加到之间的任何内容的前面和后面,
aaa 1.png bbb 2.jpg
我该如何解决这个问题? 基本上我可以从输出中删除 吗?
谢谢!
编辑:添加了 get_string_ Between 函数
function get_string_between(){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
I have this expression here
$data = file_get_contents('groups.txt');
function links1($l1, $l2){echo "<a href='". $l1 ."'><img src='". $l2 ."'/></a>";}
$parsed1 = get_string_between($data, "[Group1]", "[/Group1]");
$data = explode("\n", $parsed1);
foreach($data as $string2){
list($l1, $l2) = explode(' ', $string2);
links1($l1, $l2);}}
I have a get_string_between defined as a function above that gets anything between "[Group1]" and "[/Group1]".
The text file groups contains stuff:
[Group1]
aaa 1.png
bbb 2.jpg
[/Group1]
The problem is that when I run this it outputs as
<a href=''><img src=''/></a><a href='aaa'><img src='1.png'/></a><a href='bbb'><img src='2.jpg'/></a><a href=''><img src=''/></a>
so I get these dummy two spaces i guess that are added to the front and back of anything thats between
aaa 1.png bbb 2.jpg
How can I fix that?
Basicly gow can i remove the <a href=''><img src=''/>
from start and back from the output?
Thanks!
edit: added the get_string_between function
function get_string_between(){
$string = " ".$string;
$ini = strpos($string,$start);
if ($ini == 0) return "";
$ini += strlen($start);
$len = strpos($string,$end,$ini) - $ini;
return substr($string,$ini,$len);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
get_string_ Between
函数存在几个问题。我试图在这里清理它:希望这会帮助/引导您走向正确的方向。
There are several problems with your
get_string_between
function. I've tried to clean it up here:Hopefully this will help/lead you in the right direction.