0

how to put array values in csv in correct format? here is my code:

$title = Business - Research, MPhil/PhD | University of Greenwich | Research degrees;    
$description = '';
$keywords = '';
$list = $title.",".$keywords.",".$description;
$fp = fopen('public/scrap-meta-title-info.csv', 'a+');
        foreach ($list as $line) {
            fputcsv($fp, split(',', $line));
        }
        fclose($fp);

here is my array result: Business - Research, MPhil/PhD | University of Greenwich | Research degrees,, but when i put these values in csv then my title string break and put half value in keyword how i put title value complete in title field?

0

1 Answer 1

2

Your delimiter is , and inside of your title you have a comma. Choose another delimiter, such as ** to concatenate and split on:

Such as:

$list = $title."**".$keywords."**".$description;

fputcsv($fp, split('\*\*', $line));
Sign up to request clarification or add additional context in comments.

2 Comments

Warning: split(): REG_BADRPT in /mnt/ Warning: fputcsv() expects parameter 2 to be array, boolean
@MuhammadArif Right, my mistake. split() requires escaping of special characters defined by regexp. Therefore, we need to add \ before. Please look again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.