-1

我试图让最终输出成为

$<a style='cursor: pointer; class="photogallery-album-thumbs" onclick=fetchalbum(albumid and albumname)>

这是我知道它完全搞砸的代码。

$echo '<a style='cursor: pointer; onClick=fetchAlbum(' . $values['aid'] . "\" class='photo-gallery-album-thumbs-title' " . $values['name'] . ")>";

先感谢您。

4

3 回答 3

1

最好的办法是获得一个具有语法高亮功能的优秀代码编辑器,它是专为 PHP 编码而构建的。

但这里有一些基础知识:

<?php 
/*Standard Variable--
Anything placed between quotes is treated as a string. 
A string quote must start and end, you can continue a string but that block
must also have a start and end quote.
*/
$variable_name = "Value";
//or
$variable_name = 'Value';

//If you have a line of html with lots of double quotes, its sometime easyier to use single quotes
$variable_name = '<a style="cursor: pointer; onClick=fetchAlbum("'.$values['aid'].'") class="photo-gallery-album-thumbs-title"'.$values['name'].'")>';
//Or you have to escape the quotes or replace them with single
$variable_name = "<a style=\"cursor: pointer; onClick=fetchAlbum(\"".$values['aid']."\") class=\"photo-gallery-album-thumbs-title\"".$values['name']."\")>";
//You can also use curly brackets on double quotes but you cant use them on single
$variable_name = "<a style=\"cursor: pointer; onClick=fetchAlbum(\"{$values['aid']}\") class=\"photo-gallery-album-thumbs-title\"{$values['name']}\")>";
//Also you cant put carriage returns or tabs ect in single quotes
$variable_name = "\tSome value\r\n";
//tho yo can do
$variable_name = "\t".'Some value'.PHP_EOL;
//Using double quotes for variable assignment or printing is slower then single quotes
//Concatenation
$variable_name = "v"."a"."l"."u"."e";
//variable continuing
$variable_name .= "value";

//simple echoing out
echo 'Some value';
echo "Some value";
echo $variable_name;
print "Some value";
//or you can break out of php and put your html
?>
于 2012-04-22T07:31:56.157 回答
0

试试这条线:

echo '<a style="cursor: pointer;" onClick="fetchAlbum('.$values['aid'].')" class="photo-gallery-album-thumbs-title">'.$values['name'].'</a>';

具有相同数量的引号很重要。它们像数学中的括号一样工作。

美元符号不是必需的。表示最$有可能是一个变量。函数名不能包含圆号。

php 文档

函数名称遵循与 PHP 中其他标签相同的规则。有效的函数名称以字母或下划线开头,后跟任意数量的字母、数字或下划线。作为一个正则表达式,它将这样表示:[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

于 2012-04-22T07:03:37.447 回答
0

我认为最好使用双引号变量插值,但使用大括号 {} 引用变量。所以你的 php 很容易格式化/读取,

IE:

echo "<a style='cursor: pointer;' onClick='fetchAlbum({$values['aid']})' class='photo-gallery-album-thumbs-title' {$values['name']}>";

花括号可以很容易地避免尴尬的连接(对我来说)。

如果美元符号应该在这个锚的前面,你需要像这样逃避它:

echo "\$ ... ";

于 2012-04-22T07:06:59.850 回答