Copy link to clipboard
Copied
I have tired everything I can find to remove a carriage return from a MySQL record when creating a CSV file with no success. I have both of these statements and still the record keeps wrapping
<?php $time_candidateNotes = str_replace(array('\r\n', '\r', '\n', '\t', ',', '&hellip', '"e', '
'), ' ', $row_WADAtimes['notes']); ?>
<?php preg_replace('/\\r\\n/', " ", $time_candidateNotes); ?>
Any help greatly apprenticed.
Thanks
Copy link to clipboard
Copied
I don't use PHP, but I know there are subtle differences between single and double quotes. Try using str_replace() but wrap the array values with double quotes.
Copy link to clipboard
Copied
Instead of the above do
$rawNotes = $row_WADAtimes['notes'];
$Notesjson = json_encode($rawNotes, true);
$time_candidateNotes = json_decode($Notesjson, true);
Pushing to json and back should fix the formatting. You can always just generate the CSV from JSON going foward but this way will put you back where you started.
Edit: Sorry didn't mean to sound rude 'above' as in your code - I wasn't talking about the answer above.
Copy link to clipboard
Copied
This actually returns no value... Not sure what that means
Copy link to clipboard
Copied
Syntax error.
$rawNotes = $row_WADAtimes['notes'];
$Notesjson = json_encode($rawNotes);
$time_candidateNotes = json_decode($Notesjson, true);
There shouldn't be a 'true' on the encode, only on decode to turn it back into an object.
If that doesnt work you have have some special chars in your array that will need filtering like so:
html_entity_decode(json_encode($rawNotes));
Best way is to do a var_dump of the $Notesjson to see if it has been populated properly.
Copy link to clipboard
Copied
Just curious, did you try switching from single to double quotes?
Copy link to clipboard
Copied
I did try switching, did nothing. This is the final result, as I needed to get rid of carriage returns, commas, etc
I don't understand why I needed all this. Can someone explain what json_encode/decode does? Or why I would need all this code?
$rawCandidateName = $row_WADAtimes['candidateName'];
$CandidateNamejson = json_encode($rawCandidateName);
$time_candidateName = json_decode($CandidateNamejson, true);
$time_candidateName = trim(preg_replace("/,\n\r|\r\n/", "", $time_candidateName));
$time_candidateName = str_replace(array('\r\n', '\r', '\n', ','), ' ', $time_candidateName);
Thanks
Copy link to clipboard
Copied
$array = array('a','b','c');
var_dump($array);
echo '<br>';
$json = json_encode($array);
var_dump($json);
echo '<br>;
$backtoanarray = json_decode($json,TRUE);
var_dump($backtoanarray);
It literally just turns an array into a JSON object and then back again into an array, its a quick way to fix formatting issues rather than trying to filter it using patterns or string replace.
http://www.php.net/manual/en/language.types.array.php
Use var_dump to debug and add this at the top of your php to report errors
error_reporting(E_ALL);
ini_set("display_errors", 1);
Copy link to clipboard
Copied
Hi! Got a trial and can't find the "Databases" in WIndow>
have Mysql already running on my computer though.
Does anybody know if it is because of a trial?
Thanks!
Copy link to clipboard
Copied
There are no longer database (server) behaviors included in Dreamweaver. You must write your own code or purchase a third party extension.
By the way, adding your question to an old post that is unrelated to your question is not advised.