我已经编辑了原来的问题,因为它不再相关了,所以这是新的请求:
我有一个包含以下内容的文本文件:
Sender,Date,Subject
SolarAlert <noreply@example.com>,2019-01-11,SolarAlert Alert: DATAALRT
SolarAlert <noreply@example.com>,2019-01-11,SolarAlert Alert: NETALRT
SolarAlert <noreply@example.com>,2019-01-11,SolarAlert Alert: SFOALRT
使用以下内容,我可以引用我需要的文本(DATAALRT,NETALRT,SFOALRT)。
OPENDOC = open('Alert.txt', 'r')
READDOC = OPENDOC
for line in READDOC:
rows = [line.split(': ', 2)[-1] for line in READDOC]
newrow = rows
print(rows)
print(rows[1])
但是每行还包含一个“ \ n”。我该如何删除?
非常感谢,
答案 0 :(得分:0)
这是读取function insertNumRandom(){
$index = 0;
for($index = 0; $index<sizeof($data['data']); $index++ ) {
array_push($data[$index]['note'], rand(0,10));
}
}
并创建名为<?php
session_start();
require_once './config/config.php';
require_once 'includes/auth_validate.php';
include_once 'includes/header.php';
error_reporting (E_ALL ^ E_NOTICE);
//ONLY SUPER AND ADMINS ARE ALLOWED TO ACCESS THIS PAGE
if ($_SESSION['admin_type'] !=='admin' && $_SESSION['admin_type'] !=='super') {
$_SESSION['admin_type'] = "undefined";
echo 'Permission Denied';
exit();
}
// How can I sanatize this
$customer_id = filter_input(INPUT_GET, 'customer_id', FILTER_VALIDATE_INT);
$operation = filter_input(INPUT_GET, 'operation',FILTER_SANITIZE_STRING);
($operation == 'edit') ? $edit = true : $edit = false;
$db = getDbInstance();
$cid = htmlentities ($_GET['customer_id']);
$sql = "SELECT
(SELECT treatment_log.bdi FROM treatment_log LEFT JOIN customers ON treatment_log.treatment_fk=customers.id WHERE treatment_log.created_at=(SELECT MIN(created_at) FROM treatment_log WHERE treatment_fk = ?) AND customers.id = ?) AS first_bdi,
(SELECT treatment_log.pain FROM treatment_log LEFT JOIN customers ON treatment_log.treatment_fk=customers.id WHERE treatment_log.created_at=(SELECT MIN(created_at) FROM treatment_log WHERE treatment_fk = ?) AND customers.id = ?) AS first_pain,
(SELECT treatment_log.suicidality FROM treatment_log LEFT JOIN customers ON treatment_log.treatment_fk=customers.id WHERE treatment_log.created_at=(SELECT MIN(created_at) FROM treatment_log WHERE treatment_fk = ?) AND customers.id = ?) AS first_suicidality,
(SELECT treatment_log.bdi FROM treatment_log LEFT JOIN customers ON treatment_log.treatment_fk=customers.id WHERE treatment_log.created_at=(SELECT MAX(created_at) FROM treatment_log WHERE treatment_fk = ?) AND customers.id = ?) AS last_bdi,
(SELECT treatment_log.pain FROM treatment_log LEFT JOIN customers ON treatment_log.treatment_fk=customers.id WHERE treatment_log.created_at=(SELECT MAX(created_at) FROM treatment_log WHERE treatment_fk = ?) AND customers.id = ?) AS last_pain,
(SELECT treatment_log.suicidality FROM treatment_log LEFT JOIN customers ON treatment_log.treatment_fk=customers.id WHERE treatment_log.created_at=(SELECT MAX(created_at) FROM treatment_log WHERE treatment_fk = ?) AND customers.id = ?) AS last_suicidality,
(SELECT CAST(treatment_log.created_at as DATE) FROM treatment_log LEFT JOIN customers ON treatment_log.treatment_fk = customers.id WHERE treatment_log.created_at = (SELECT MAX(created_at) FROM treatment_log WHERE treatment_fk = ?)AND customers.id = ?) AS last_visit,
(SELECT COUNT(*) FROM treatment_log WHERE treatment_fk = ?) AS completed_treatments,
(SELECT COUNT(*) FROM treatment_log WHERE treatment_fk = ? AND missed_treatment='yes') AS number_of_missed_treatments,
(SELECT COUNT(*) FROM bdi WHERE bdi_fk = ?) AS completed_bdis,
(SELECT customers.f_name FROM customers WHERE customers.id = ?) AS f_name,
(SELECT customers.l_name FROM customers WHERE customers.id = ?) AS l_name,
(SELECT customers.status FROM customers WHERE customers.id = ?) AS status,
(SELECT customers.mrn FROM customers WHERE customers.id = ?) AS mrn,
(SELECT customers.ohip FROM customers WHERE customers.id = ?) AS ohip,
(SELECT customers.sex FROM customers WHERE customers.id = ?) AS sex,
(SELECT customers.address FROM customers WHERE customers.id = ?) AS address,
(SELECT customers.city FROM customers WHERE customers.id = ?) AS city,
(SELECT customers.postal_code FROM customers WHERE customers.id = ?) AS country,
(SELECT customers.phone FROM customers WHERE customers.id = ?) AS phone,
(SELECT customers.about FROM customers WHERE customers.id = ?) AS about,
(SELECT customers.date_of_birth FROM customers WHERE customers.id = ?) AS date_of_birth,
(SELECT customers.protocol FROM customers WHERE customers.id = ?) AS protocol,
(SELECT customers.treatment_location FROM customers WHERE customers.id = ?) AS treatment_location,
(SELECT customers.area FROM customers WHERE customers.id = ?) AS area,
(SELECT customers.dx FROM customers WHERE customers.id = ?) AS dx,
(SELECT customers.room FROM customers WHERE customers.id = ?) AS room,
(SELECT customers.coil FROM customers WHERE customers.id = ?) AS coil,
(SELECT customers.target_threshold FROM customers WHERE customers.id = ?) AS target_thresold,
(SELECT customers.number_of_treatments FROM customers WHERE customers.id = ?) AS number_of_treatments,
(SELECT customers.motor_threshold FROM customers WHERE customers.id = ?) AS motor_threshold,
(SELECT customers.threshold_multiplier FROM customers WHERE customers.id = ?) AS threshold_multiplier,
(SELECT customers.created_at FROM customers WHERE customers.id = ?) AS created_at,
(SELECT customers.updated_at FROM customers WHERE customers.id = ?) AS updated_at;";
$stmt = mysqli_stmt_init($conn);
mysqli_stmt_prepare($stmt, $sql);
mysqli_stmt_bind_param($stmt, "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid, $cid);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
?>
的变量,其值为'Alert.txt'
的脚本:
rows
但是每行还包含一个“ \ n”。我该如何删除?
要删除字符串末尾的“ \ n”,只需使用['DATAALRT', 'NETALRT', 'SFOALRT']
。