chimsik chimsik - 10 days ago 5
MySQL Question

In PHP code, how can I remove newlines

In my PHP code

$sql = "SELECT a.SEQ, a.DPCODE, a.SUBJECT, CONCAT_WS('~',a.SDATE, a.EDATE) AS SDATE, b.content, concat(replace(c.filepath,'E:/WWW','http://myhome.com/'),c.filelocalnm) as filename";
$sql .= " FROM PJ_EXHIBIT a LEFT JOIN collection.exhibit b ON a.SEQ=b.seqno LEFT JOIN sy_file c ON a.attach_file = c.SEQ";


with
json_encode
, it returns:

result in explorer

I want to remove '\'.

Answer

You can use str_replace

<?php
$variable = 'http:\/\/comin.com:8990\/\/upload\/pj\/PJ_EXHIBIT\/1480308974751289.jpg';
$new = str_replace('\\', '', $variable);
echo $new;
?>

Or you can use preg_replace

<?php
$variable = 'http:\/\/comin.com:8990\/\/upload\/pj\/PJ_EXHIBIT\/1480308974751289.jpg';
$new = preg_replace("/\\\/", '', $variable);
echo $new;    
?>

Manuals

More informations can be found below: