我正在尝试使用php检查两个字符串是否匹配,如果它们匹配,则执行某些操作。
但我的if语句仍然返回false,即使它们匹配。
查看我的VIEW文件。在if语句之前,我甚至使用echo来查看它们是什么。
我错过了什么?它与angularjs有关吗???
顺便说一下,echo $type . " " . '{{ post.postType }}';
实际上会产生这样的结果:
<!-- The View -->
<body ng-app"myApp">
<div class="container testing" ng-controller="feedControl">
<table>
<tr ng-repeat="post in posts">
<td style="padding:15px">{{ post.postType }}</td>
<td style="padding:15px">{{ post.postTitle }}</td>
<td style="padding:15px">{{ post.postDescription }}</td>
<td style="padding:15px">{{ post.postDate }}</td>
<td style="padding:15px">
<?php
$type = '{{ post.postType }}';
echo $type . " " . '{{ post.postType }}';
if($type == 'image'){
echo $type . " " . '{{ post.postType }}';
};
?>
</td>
</tr>
</table>
<br>
</div>
</body>
<!-- feed.php -->
<?php
include 'db.php';
connection();
$sql = "SELECT * FROM feed ORDER BY time DESC";
$result = $conn->query($sql);
$outp = "";
while($rs = $result->fetch_array(MYSQLI_ASSOC)) {
if ($outp != "") {$outp .= ",";}
$source = "";
if($rs["post_type"] == "video"){
$source = str_replace('<iframe width="560" height="315" src="', '', $rs["src"]);
$source = str_replace('" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>', '', $source);
}
if($rs["post_type"] == "music"){
$source = str_replace('<iframe width="100%" height="300" scrolling="no" frameborder="no" allow="autoplay" src="', '', $rs["src"]);
$source = str_replace('"></iframe>', '', $source);
}
if($rs["post_type"] == "image"){
$source = $rs["src"];
}
$outp .= '{"postType":"' . $rs["post_type"] . '",';
$outp .= '"postDate":"' . $rs["time"] . '",';
$outp .= '"postTitle":"' . $rs["post_title"] . '",';
$outp .= '"src":"' . $source . '",';
$outp .= '"postDescription":"'. $rs["post_description"] . '"}';
}
$outp ='{"records":['.$outp.']}';
connectionClose();
echo($outp);
?>
<!-- module -->
var app = angular.module("myApp", ["ngRoute"]);
<!-- controller -->
app.controller('feedControl', function($scope, $http) {
$http.get("pages/db_section/feed.php")
.then(function (response) {
$scope.posts = response.data.records;
});
});