Forum Moderators: open
SELECT `id` , `title` , `alias` , `introtext` , `fulltext`
FROM `jos_content` Export : CSV
Fields terminated by : #
Fields enclosed by : "
Fields escaped by : \
Lines terminated by : AUTO
Replace NULL by : NULL <?php
//>
//&$arr must be an array
//$findRegEx should be a regular expression, what to find in strings in the array
//$replacement should be a string, what items found in the array will be replaced with
function replaceInArray(&$arr, $findRegEx, $replacement) {
foreach ($arr as $k => $v) {
if (is_string($arr[$k])) {
$arr[$k] = preg_replace($findRegEx, $replacement, $arr[$k]);
}
}
}
//connect to mysql database, note you need to insert your password below
$sql = mysql_connect("localhost", "YOUR_PASSWORD_HERE");
if (!sql) {
die('Unable To Connect!'); //adjust username, password as needed...
}
//select database, note you need to enter your database name below
mysql_select_db('NAME_OF_DATABASE_TO_SELECT_HERE', $sql);
$result = mysql_query('SELECT id,title,alias,introtext,fulltext FROM jos_content', $sql);
//open existing or create new file named 'info_csv.csv'
//the 'w' flag will allow to overwrite any file with the given name if it already exists!
$file = fopen('info_csv.csv', 'w');
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
//The second argument being passed to replaceInArray below is a regular expression
//which says to find line feed characters which may or may not be surrounded by one or more single spaces
//I'm unsure whether you will want to replace line feeds with '<br>' or a single blank space ' '
//so adjust the third argument in the call to replaceInArray below to suit needs
replaceInArray($row, '/\s*[\r\n]+\s*/', ' ');
fputcsv($file, $row);
}
fclose($file);
?>