Jump to content

Recommended Posts

Hi:

I have file a.csv that contains multiple columns and data. I want to replace all "</br>" tags in file a.csv with "<br />" and then save it to file b.csv

 

I am using the following code but it is not working:

 

<?

// File to open
$file = 'a.csv';

// Search and Replace Arrays
$search = array('</br>');
$replace = array('<br />');

// Open the file
$lines = file($file);

// Read through the file
foreach($lines as $line_num => $line) {
    $text = preg_replace($search, $replace, $line);
}

// Save the file
$save = $text->save ("b.csv");

?>

Link to comment
https://forums.phpfreaks.com/topic/136628-how-to-use-preg_replace/
Share on other sites

Ok, I'm using this code:

 

<?

// File to open
$file = 'a.csv';

// Search and Replace Arrays
$search = array('</br>');
$replace = array('<br />');

// Open the file
$lines = file($file);

// Read through the file
foreach($lines as $line_num => $line) {
    $text = str_replace($search, $replace, $line);
}

// Save the file
$save = $text->save ("b.csv");

?> 

 

and I'm getting this error:

 

Fatal error: Call to a member function save() on a non-object in C:\localhost\test\process\replace.php on line 18

 

Apperantly the save function is not working.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.