doc1355 Posted December 12, 2008 Share Posted December 12, 2008 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 More sharing options...
ted_chou12 Posted December 12, 2008 Share Posted December 12, 2008 in that case, since u have specific variable, try: $text = str_replace($search, $replace, $line); Link to comment https://forums.phpfreaks.com/topic/136628-how-to-use-preg_replace/#findComment-713377 Share on other sites More sharing options...
doc1355 Posted December 12, 2008 Author Share Posted December 12, 2008 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. Link to comment https://forums.phpfreaks.com/topic/136628-how-to-use-preg_replace/#findComment-713382 Share on other sites More sharing options...
ted_chou12 Posted December 12, 2008 Share Posted December 12, 2008 I think is the problem saving the file, ??? but I am not sure about these functions, Ted. Link to comment https://forums.phpfreaks.com/topic/136628-how-to-use-preg_replace/#findComment-713384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.