[英]Can you do implode .= in php?
Not sure if I ask this correctly, correct me if I am wrong. 不知道我是否正确地问了,如果我错了,请纠正我。 I know you need an array to do implode, Instead adding a space after </a>
, I want to do an implode in .=
我知道您需要一个数组进行内爆,而不是在</a>
之后添加一个空格,我想在.=
进行内爆
for ($i=1; $i<=$lastPage; $i++) {
$pageLink .= "<a href='ajax.php?action=merchantlist&merchant_id=" . $merchant_id . "p=".$i."'>".$i."</a>";
};
$pageLinks = implode(' ', $pageLink);
.= Means to append to the previously defined variable (string mostlikely). 。=表示要附加到先前定义的变量(最有可能是字符串)。 So in your case you are alrady craeting a string out of your loop to the exception that your variable has not been initialized. 因此,在您的情况下,您很想将循环之外的字符串添加到变量中,因为您的变量尚未初始化。
So you could do something like this and remove the implode: 因此,您可以执行以下操作并移除爆破:
$pageLink="";
for ($i=1; $i<=$lastPage; $i++) {
$pageLink .= "<a href='ajax.php?action=merchantlist&merchant_id=" . $merchant_id . "p=".$i."'>".$i."</a>";
};
echo $pageLink;
or create an array (like your original question is asking for) but i think it is an unessecary step. 或创建一个数组(如您的原始问题所要求的),但我认为这是不安全的步骤。 (initalize an array, to call an function to make the string) as when you could just use 1 varaible and avoid the function threshold by appending to it (like in my 1st snippet). (初始化一个数组,以调用函数来创建字符串),就像您可以只使用1个变量,并通过将其附加到函数阈值来避免函数阈值一样(如我的第一个代码片段)。
for ($i=1; $i<=$lastPage; $i++) {
$pageLink[] = "<a href='ajax.php?action=merchantlist&merchant_id=" . $merchant_id . "p=".$i."'>".$i."</a>";
};
$pageLinks = implode(' ', $pageLink);
echo $pageLinks;
also i think you are missing an & in your string before the "p=" 我也认为您在字符串“ p =”之前缺少&
$pageLink .= "<a href='ajax.php?action=merchantlist&merchant_id=" . $merchant_id . "p=".$i."'>".$i."</a>";
should be with an & before the p= like so 应该像这样在p =之前带有&
$pageLink .= "<a href='ajax.php?action=merchantlist&merchant_id=" . $merchant_id . "&p=".$i."'>".$i."</a>";
Another thing, i would url_encode anything in your href that could be a string so an appostrophe won'T break your html attribute. 另一件事,我会对您的href中的任何内容进行url_encode编码,因为它可能是字符串,所以一个开篇不会破坏您的html属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.