我從包含需要刪除的轉義斜槓的PHP文件返回數據。我創建了一個多維數組的返回對象。我用json_encode($data, JSON_UNESCAPED_SLASHES)
返回它,但斜槓沒有被刪除。PHP不刪除轉義斜槓
我自己也嘗試了涉及使用雖然和stripslashes()
甚至沒有工作在陣列中的每個單獨的串循環不同的方法。
我有沒有麻煩所需要的數據在正確的JSON結構返回,但我似乎無法擺脫這些斜線!
$data = array('bodyCopy' => array(), 'projects' => array());
$sql = "SELECT * FROM " . $table;
$result = mysqli_query($conn, $sql) or die("Error in Selecting " . mysqli_error($conn));
while($row = mysqli_fetch_assoc($result)) {
$data['bodyCopy'] = $row;
}
$sql = "SELECT * FROM experienceSectionProjects";
$result = mysqli_query($conn, $sql) or die("Error in Selecting " . mysqli_error($conn));
while($row = mysqli_fetch_assoc($result)) {
array_push($data['projects'], $row);
}
echo json_encode($data, JSON_UNESCAPED_SLASHES);
我返回對象洛斯這樣的:
編輯 這裏是包含斜槓一些真實的數據:
{
"bodyCopy":{
"title":"Experience's",
"headerIcon":"briefcase",
"introCopy":"Don't",
"gridHeader":"header"
},
"projects":[
{
"id":"1",
"company":"Medical Mutual",
"position":"UI Developer",
"logo":"medmutual.png",
"backgroundImg":"medMutual.jpg",
"projectSummary":"Online enrollment application for health insurance marketplace",
"description":"I work as the dedicated front end developer on the online enrollment application for the Medical Mutual Individual Insurance Marketplace and Medicare Advantage Marketplace. As front end developer my main responsibility is generating HTML/CSS/JS for the users interface. I collaborate with server side developers in an C#.NET MVC environment to create dynamic content and integrate the code from the UI into Sitecore. Aside from the Online Enrollment applications, I am involved with developing other public facing websites for the company including an internal recruitment website."
},
{
"id":"2",
"company":"Macy\'s",
"position":"UI/AngularJS Developer",
"logo":"macys.png",
"backgroundImg":"macys.jpg",
"projectSummary":"CRM software for in store sales associates",
"description":""
}
]
}
編輯
這可能會更多信息。這是我正在寫值到數據庫:
$projects = $p['projects'];
if(is_array($projects)) {
foreach ($projects as $project) {
$id = $project['id'];
$company = mysqli_real_escape_string($conn, $project['company']);
$position = mysqli_real_escape_string($conn, $project['position']);
$logo = mysqli_real_escape_string($conn, $project['logo']);
$backgroundImg = mysqli_real_escape_string($conn, $project['backgroundImg']);
$projectSummary = mysqli_real_escape_string($conn, $project['projectSummary']);
$description = mysqli_real_escape_string($conn, $project['description']);
$Query = $conn->prepare("INSERT INTO experienceSectionProjects (id, company, position, logo, backgroundImg, projectSummary, description)
VALUES (?, ?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE company = VALUES(company), position = VALUES(position), logo = VALUES(logo), backgroundImg = VALUES(backgroundImg), projectSummary = VALUES(projectSummary), description = VALUES(description)");
$Query->bind_param('issssss', $id, $company, $position, $logo, $backgroundImg, $projectSummary, $description);
$Query->execute();
$Query->close();
}
}
你在哪裏看到斜槓? – Ctx
爲了便於閱讀,我刪除了真實數據,因爲我不認爲這很重要,但如果您認爲它可以幫助您,我會添加一些真實數據。 – Ian
您是否驗證了恆定是您認爲的常數? – Rooster