-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はフォーマット/読み取りが非常に簡単です。

すなわち:

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

中括弧を使用すると、(私にとっては)扱いにくい連結を簡単に回避できます。

ドル記号がこのアンカーの前にあるはずの場合は、次のようにエスケープする必要があります。

echo "\$ ... ";

于 2012-04-22T07:06:59.850 に答える