我有以下PHP代码:
$temp_str .= '
<table width="300" height="84" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="80" rowspan="4"><img src="img/planets/1sm.jpg" width="80" height="82" /></td>
<td width="110">System '.$user[location].'</td>
<td width="110">'.$planets[planet_name].'</td>
</tr>
<tr>
<td colspan="2">This planet is guarded by '.$planets[fighters].' Fighters</td>
</tr>
<tr>
<td colspan="2">Clan ID</td>
</tr>
<tr>
<td>Attack</td>
<td>Special Weapon</td>
</tr>
</table>
';足够简单,而且显示得很漂亮。
我尝试在Attack和Special weapon框中插入以下内容;
攻击;
if(($planets['login_id'] == $user['login_id']) ||
($planets['clan_id'] == $user['clan_id'] &&
$planets['clan_id'] != 0) || ($user['login_id'] == ADMIN_ID) ||
($planets['fighters'] == 0) || $user['ship_id'] == NULL) {
$temp_str .= "- <a href=planet.php?planet_id=$planets[planet_id]><img src=\"img/icons/Land.png\" alt=\"Land\" /></a>";
} else {
if($flag_planet_attack != 0){
$temp_str .= "- <a href=planet.php?planet_id=$planets[planet_id]&attack_planet=1><img src=\"img/icons/Attack.png\" alt=\"Attack\" /></a>";特种武器;
if(ereg("sv",$user_ship['config'])) { //quark disrupter
$temp_str .= " - <a href=attack.php?quark=1&planet_num=$planets[planet_id]>Fire Quark Displacer</a>";
} elseif(ereg("sw",$user_ship['config']) && $enable_superweapons == 1) { //terra maelstrom
$temp_str .= " - <a href=attack.php?terra=1&planet_num=$planets[planet_id]>Fire Terra Maelstrom</a>";
}
if($planets['pass'] != '0') {
$temp_str .= " - <a href=planet.php?planet_id=$planets[planet_id]>Have Pass</a>";但是我总是收到意外的t_string,>所有的错误。
有人能告诉我我哪里做错了吗?非常感谢您的帮助。
下面是我正在尝试的完整代码...分裂,我猜:
if(($planets['login_id'] == $user['login_id']) ||
($planets['clan_id'] == $user['clan_id'] &&
$planets['clan_id'] != 0) || ($user['login_id'] == ADMIN_ID) ||
($planets['fighters'] == 0) || $user['ship_id'] == NULL) {
$temp_str .= "- <a href=planet.php?planet_id=$planets[planet_id]><img src=\"img/icons/Land.png\" alt=\"Land\" /></a>";
} else {
if($flag_planet_attack != 0){
$temp_str .= "- <a href=planet.php?planet_id=$planets[planet_id]&attack_planet=1><img src=\"img/icons/Attack.png\" alt=\"Attack\" /></a>";
if(ereg("sv",$user_ship['config'])) { //quark disrupter
$temp_str .= " - <a href=attack.php?quark=1&planet_num=$planets[planet_id]>Fire Quark Displacer</a>";
} elseif(ereg("sw",$user_ship['config']) && $enable_superweapons == 1) { //terra maelstrom
$temp_str .= " - <a href=attack.php?terra=1&planet_num=$planets[planet_id]>Fire Terra Maelstrom</a>";
}
if($planets['pass'] != '0') {
$temp_str .= " - <a href=planet.php?planet_id=$planets[planet_id]>Have Pass</a>";
}
}
}
}
$planets = dbr(1);
}//end while
}这就是我想要实现的目标,但似乎我留下了一些东西。
$temp_str .= '
<table width="300" height="84" border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="80" rowspan="4"><img src="img/planets/1sm.jpg" width="80" height="82" /></td>
<td width="110">System '.$user[location].'</td>
<td width="110">'.$planets[planet_name].'</td>
</tr>
<tr>
<td colspan="2">This planet is guarded by '.$planets[fighters].' Fighters</td>
</tr>
<tr>
<td colspan="2">Clan ID</td>
</tr>
<tr>
<td>';
if(($planets['login_id'] == $user['login_id']) ||
($planets['clan_id'] == $user['clan_id'] &&
$planets['clan_id'] != 0) || ($user['login_id'] == ADMIN_ID) ||
($planets['fighters'] == 0) || $user['ship_id'] == NULL) {
$temp_str .= "- <a href=planet.php?planet_id=$planets[planet_id]><img src=\"img/icons/Land.png\" alt=\"Land\" /></a>";
} else {
if($flag_planet_attack != 0){
$temp_str .= "- <a href=planet.php?planet_id=$planets[planet_id]&attack_planet=1><img src=\"img/icons/Attack.png\" alt=\"Attack\" /></a></td>
<td>";
if(ereg("sv",$user_ship['config'])) { //quark disrupter
$temp_str .= " - <a href=attack.php?quark=1&planet_num=$planets[planet_id]>Fire Quark Displacer</a>";
} elseif(ereg("sw",$user_ship['config']) && $enable_superweapons == 1) { //terra maelstrom
$temp_str .= " - <a href=attack.php?terra=1&planet_num=$planets[planet_id]>Fire Terra Maelstrom</a>";
}
if($planets['pass'] != '0') {
$temp_str .= " - <a href=planet.php?planet_id=$planets[planet_id]>Have Pass</a>";
}
}
}
}
$planets = dbr(1);
}//end while
}
</td>
</tr>
</table>
';发布于 2011-08-03 06:57:27
在字符串中提到数组值时,需要将其括在{和}中。示例:
$temp_str .= " - <a href=attack.php?quark=1&planet_num={$planets['planet_id']}>Fire Quark Displacer</a>";或
$temp_str .= " - <a href=attack.php?quark=1&planet_num=" . $planets['planet_id'] . ">Fire Quark Displacer</a>";发布于 2011-08-03 06:58:12
在<a>标记的href中有"planet.php?planet_id=$planets[planet_id]>Have Pass</a>",planet_id是一个变量还是一个键?因为它是双引号的,所以您可以执行类似"planet.php?planet_id={$planets['planet_id']}>Have Pass</a>"的操作
发布于 2011-08-03 06:58:53
不知道你是如何把它‘放’进‘一个盒子’的,但是如果你想让一个字符串包含它所封装的引号,你应该转义这些引号,如下所示:
$string = 'This is a text with quotes. Don\'t forget to escape';使用双引号可能更容易。请注意,与单引号字符串不同,您可以在双引号字符串中使用变量,因此$string = "--- $a ---"将在字符串中填充$a的值。
$string = "Single 'quotes' can be used in double-quote-embedded strings";如果你需要在你的PHP代码中嵌入大量的超文本标记语言或者JavaScript代码,你可能需要使用下面的代码:
$string = <<<AnyIdentifier
Any text containing special characters. Note that variables are parsed in
these strings too.
AnyIdentifier;
// Note, closing identifier must occur at the start of the line.编辑
// Code to create weapon HTML goes here. Rename $temp_str to $weaponCode
....
if($flag_planet_attack != 0){
$weaponCode .= "- <a href=planet.php?planet_id=$planets[plane
.....
// Code to create attack HTML goes here. Rename $temp_str to $attackCode
$attackCode = '... Generated Attack HTML';
$temp_str = <<<totalHtml
<table>
<!-- Note how you can use variables inside this kind of string declaration. -->
<tr>$weaponCode</tr><tr>$attackCode</tr>
</table>
totalHtml;
// String declaration ends on the line above. Note that that line must not
// contain leading not trailing spaces.https://stackoverflow.com/questions/6919677
复制相似问题