我在PHP中遇到语法错误问题。感谢有人能帮我理解这里出了什么问题。
解析错误:语法错误,意外T_CONSTANT_ENCAPSED_STRING,期待','或';'在:
导致此问题的一行是:
if ($custom_logo){
echo '#logo a { background: url(''.$custom_logo.'') left center no-repeat; }';
}
答案 0 :(得分:2)
当你想要使用2次单引号时,你需要使用转义字符...
if ($custom_logo){ echo '#logo a { background: url(\''.$custom_logo.'\') left center no-repeat; }'; }
答案 1 :(得分:1)
使用 heredoc 是另一种方法,请确保LOGO_CSS是该行的第一个文本,没有前导空格。
var board = [
["m","t","h","v","g","y","m","w","n","q"],
["q","e","v","f","a","k","n","c","c","k"],
["x","s","r","e","r","c","m","c","h","a"],
["j","z","f","w","g","i","o","t","b","l"],
["x","v","j","m","x","q","s","s","v","c"],
["m","i","i","a","e","u","t","t","j","m"],
["t","n","j","w","h","j","e","m","b","d"],
["v","n","t","f","r","y","b","q","v","a"],
["k","q","x","b","q","w","c","i","v","g"],
["s","o","m","e","t","h","i","n","g","t"]
];
const directions = [
'horizontal',
'vertical'
];
function chooseRandomPlace() {
return [Math.floor(Math.random() * 10),
Math.floor(Math.random() * 10)];
}
let i = 0;
function horizontal(word) {
i++;
console.log(i);
let wordLength = word.length;
let [x, y] = chooseRandomPlace();
if (9 - y < wordLength) return horizontal(word);
for (let i = 0; i < wordLength; i++) {
if (typeof board[x][y + i] !== 'string') {
return horizontal(word)
}
}
for (let i = 0; i < wordLength; i++) {
board[x][y + i] = {value: word[i]};
}
}
function vertical(word) {
i++;
console.log(i);
let wordLength = word.length;
let [x, y] = chooseRandomPlace();
if (9 - x < wordLength) return vertical(word);
for (let i = 0; i < wordLength; i++) {
if (typeof board[x + i][y] !== 'string') {
return vertical(word);
}
}
for (let i = 0; i < wordLength; i++) {
board[x + i][y] = {value: word[i]};
}
}
function alocate(word) {
let direction = directions[Math.floor(Math.random() * directions.length)];
if (direction === 'horizontal') {
horizontal(word)
} else {
vertical(word);
}
console.log(JSON.stringify(board));
}
const words = ['SOMETHIN', 'SOMETHIN', 'SOMETHIN', 'SOMETHIN', 'SOMETHIN'];
for (let word of words) {
let location = alocate(word);
}
http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc