【发布时间】:2021-06-09 01:32:40
【问题描述】:
任何机构都可以提供帮助。如何从 TSQL 数据库提取的数据中删除 \r\n?我使用 PHP 来检索数据。
http://localhost/model1.php?model=ROLL
$model = (isset($_GET['model'])) ? $_GET['model'] : '';
$model = str_replace('\r\n','', $model);
if ($model != '') {
$tsql = "SELECT Brand,Model from product where Model LIKE '%$model%'";
$stmt = sqlsrv_query( $conn, $tsql );
$result = array();
$row_check = sqlsrv_has_rows( $stmt );
if ($row_check == true) {
while ($row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)) {
$result['Response'][] = array(
'Brand' => $row['Brand'],
'Model' => $row['Model']
);
}
}
..
..
..
header('Content-Type: application/json');
echo json_encode($result, true);
die();
【问题讨论】:
-
str_replace("\r\n","", $str) -
str_replace("\r\n"," ", $str)
-
我已经实现了这个..但是什么也没发生.. $model = str_replace('\r\n','', $model);
-
你确定你的 $model 变量有你认为的文本吗?临时放置一个 print_r($model); 可能是个好主意。在该代码的第一行之前的行,以查看该变量包含的内容。 :)
-
$model 来自 URL 参数..