我正在运行以下PHP代码:
<?php
</script>
?>
Run Code Online (Sandbox Code Playgroud)
没有解析错误,输出是 " ?>"(例子).
在类似的情况下,我得到一个解析错误:
<?php
</div>
?>
Run Code Online (Sandbox Code Playgroud)
解析错误:语法错误,意外的'<'在......
为什么不<?php </script> ?>给出同样的错误?
我收到一个错误:
Parse error: syntax error, unexpected end of file in the line
Run Code Online (Sandbox Code Playgroud)
使用此代码:
<html>
<?php
function login()
{
// Login function code
}
if (login())
{?>
<h2>Welcome Administrator</h2>
<a href=\"upload.php\">Upload Files</a>
<br />
<a href=\"points.php\">Edit Points Tally</a>
<?php}
else
{
echo "Incorrect login details. Please login";
}
?>
Some more HTML code
</html>
Run Code Online (Sandbox Code Playgroud)
有什么问题?
我使用jQuery版本1.5.1来执行以下ajax调用:
$.ajax({
dataType: 'jsonp',
data: { api_key : apiKey },
url: "http://de.dawanda.com/api/v1/" + resource + ".json",
success: function(data) { console.log(data); },
error: function(jqXHR, textStatus, errorThrown) { console.log(errorThrown); console.log(textStatus); }
});
Run Code Online (Sandbox Code Playgroud)
服务器使用有效的json对象进行响应:
{
"response": {
"type":"category",
"entries":1,
"params":{
"format":"json",
"api_key":"c9f11509529b219766a3d301d9c988ae9f6f67fb",
"id":"406",
"callback":"jQuery15109935275333671539_1300495251986",
"_":"1300495252693"
},
"pages":1,
"result":{
"category":{
"product_count":0,
"id":406,
"restful_path":"/categories/406",
"parent_id":null,
"name":"Oberteile"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是从不调用成功回调,而是错误回调产生了这个输出:
jQuery15109935275333671539_1300495251986 was not called
parsererror
Run Code Online (Sandbox Code Playgroud)
为什么会这样?
我没有使用jQuery的额外库.
编辑:
如果我尝试使用"json"作为dataType而不是"jsonp"进行ajax调用,则服务器以空字符串响应.
如何使用自定义错误处理程序处理解析和致命错误?
我收到以下错误:
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in.. on line 52.
Run Code Online (Sandbox Code Playgroud)
第52行是if ($result = mysqli->query....如果我注释掉该行,则会发生相同的错误$mysqli->query("INSERT INTO....
为什么会出错?
$unique_code = "";
$inserted = false;
while(!$inserted) {
$unique_code = generateCode();
echo $unique_code;
// Check if it exists
if ($result = mysqli->query("SELECT unique_code FROM coming_soon_emails WHERE unique_code = '$unique_code'")) {
// Check no record exists
if ($result->num_rows == 0) {
// Create new record
$mysqli->query("INSERT INTO coming_soon_emails (email,unique_code) VALUES ('" . $mysqli->real_escape_string($_POST['email']) . "','$unique_code')");
// Set inserted to true …Run Code Online (Sandbox Code Playgroud) 当我尝试从http://api-v3.deezer.com/1.0/search/album/?q=beethoven&index=2&nb_items=2&output=json获取JSON 时:
(jQuery 1.6.2)
$.ajax({
type: "GET",
url: url,
dataType: "jsonp",
success: function (result) {
alert("SUCCESS!!!");
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.statusText);
alert(xhr.responseText);
alert(xhr.status);
alert(thrownError);
}
});
Run Code Online (Sandbox Code Playgroud)
我明白了: parsererror; 200; undefined; jquery162******************** was not called
但是使用http://search.twitter.com/search.json?q=beethoven&callback=?&count=5中的JSON 工作正常.两者都是有效的JSON格式.那么这个错误是什么?
[UPDATE]
@ 3ngima,我在asp.net中实现了这个,它运行正常:
$.ajax({
type: "POST",
url: "WebService.asmx/GetTestData",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
alert(result.d);
}
});
Run Code Online (Sandbox Code Playgroud)
WebService.asmx:
[WebMethod]
public string GetTestData()
{
try
{
var req = System.Net.HttpWebRequest.Create("http://api-v3.deezer.com/1.0/search/album/?q=beethoven&index=2&nb_items=2&output=json");
using (var resp …Run Code Online (Sandbox Code Playgroud) 在PHP中,您可以通过or die在遇到某些错误时调用exit 来处理错误,如下所示:
$handle = fopen($location, "r") or die("Couldn't get handle");
Run Code Online (Sandbox Code Playgroud)
使用die()不是处理错误的好方法.我宁愿返回一个错误代码,以便父函数可以决定做什么,而不是只是不正确地结束脚本并向用户显示错误.
然而,PHP显示错误,当我尝试更换or die使用or return,这样的:
$handle = fopen($location, "r") or return 0;
Run Code Online (Sandbox Code Playgroud)
为什么or die()工作,但不是or return 0?
我的脚本在我的xampp上运行得非常好.现在我尝试将其上传到服务器上,但它直接吐了一个
解析错误:语法错误,意外'['
在我的脸上.:(
它嘲弄的线是这一行:
$item = $xml->xpath($path)[0];
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题.我试着看看php 5.3更新日志,但没有找到任何关于它.(因为我在服务器上有5.3,而在xampp上有一个较旧的版本)
整个代码块看起来像这样:
$path = '//item[@id="'.$id.'"]';
if ($xml->xpath($path)) {
$item = $xml->xpath($path)[0];
} else {
die('<p class="error">Script Error: Code 101 - Please contact administrator</p>');
}
Run Code Online (Sandbox Code Playgroud)
我感谢任何帮助,我无法与谷歌联系并且不知道它可能来自哪里,因为在xampp它的工作正常
谁喜欢告诉我这段代码有什么问题(语法上)?
-- merge two sorted lists
mergeX [] b res = b ++ res
mergeX a [] res = a ++ res
mergeX a:as b:bs res
| a > b = mergeX as b:bs a:res
| otherwise = mergeX a:as bs b:res
Run Code Online (Sandbox Code Playgroud)
解释:
解析模式中的错误:mergeX
我的代码出了什么问题?我在我的测试服务器上运行了代码并且代码工作正常但是当我将它上传到我的生产服务器时,我得到了
Parse error: syntax error, unexpected T_FUNCTION in /hermes/bosweb/web013/b130/ipg.acrsflcom/darayngedbeats/gentest.php on line 10
Run Code Online (Sandbox Code Playgroud)
这是我的代码
$old = "http://darayngedbeats1.s3.amazonaws.com /mp3/CrazyMonsta2.mp3?AWSAccessKeyId=AKIAJXA36ESCLQHCB54Q&Expires=1297279906& Signature=HD36ZQE8yeTIW6JPWKMcciPTiTs%3D"; //enter the key that needs to be converted
$search = array(":","?","=","&","%");
$replace = array("%3A","%3F","%3D","%26","%25");
function search_replace($s,$r,$sql)
{ $e = '/('.implode('|',array_map('preg_quote', $s)).')/';
$r = array_combine($s,$r);
return preg_replace_callback($e, function($v) use ($s,$r) { return $r[$v[1]]; },$sql);
}
echo "<br><br>";
$new = search_replace($search,$replace,$old);
echo $new;
?>
Run Code Online (Sandbox Code Playgroud) parse-error ×10
php ×7
jquery ×2
fatal-error ×1
haskell ×1
html ×1
internals ×1
javascript ×1
jquery-1.5 ×1
json ×1
jsonp ×1
mysql ×1
object ×1
php-5.3 ×1
return ×1
syntax ×1