akiznin Posted June 17, 2009 Share Posted June 17, 2009 How can I make it so my php script will delete everything in between "< >" (without quotes) and delete the arrows as well? Link to comment https://forums.phpfreaks.com/topic/162662-find-and-delete-strings/ Share on other sites More sharing options...
mike12255 Posted June 17, 2009 Share Posted June 17, 2009 were is this all located? a txt file, a database? we need info Link to comment https://forums.phpfreaks.com/topic/162662-find-and-delete-strings/#findComment-858470 Share on other sites More sharing options...
akiznin Posted June 18, 2009 Author Share Posted June 18, 2009 text file Link to comment https://forums.phpfreaks.com/topic/162662-find-and-delete-strings/#findComment-858538 Share on other sites More sharing options...
Ken2k7 Posted June 18, 2009 Share Posted June 18, 2009 preg_replace('<[^>]*>','',$str); Link to comment https://forums.phpfreaks.com/topic/162662-find-and-delete-strings/#findComment-858571 Share on other sites More sharing options...
akiznin Posted June 18, 2009 Author Share Posted June 18, 2009 i get an error.. <?php $ourFileName = "test.txt"; $fh = fopen($ourFileName, 'r+') or die("Can't open file"); echo preg_replace('<[^>]*>','',$fh); fclose($fh); ?> Link to comment https://forums.phpfreaks.com/topic/162662-find-and-delete-strings/#findComment-858584 Share on other sites More sharing options...
xtopolis Posted June 18, 2009 Share Posted June 18, 2009 Use file_get_contents / file_put_contents. In your script, $fh points to stream, not the data as a string. fopen() binds a named resource, specified by filename , to a stream. $fn = "test.txt"; $file = file_get_contents($fn); $file = preg_replace('<[^>]*>','',$file); file_put_contents($fn, $file); Untested. Link to comment https://forums.phpfreaks.com/topic/162662-find-and-delete-strings/#findComment-858619 Share on other sites More sharing options...
akiznin Posted June 18, 2009 Author Share Posted June 18, 2009 i get another error.. Warning: preg_replace() [function.preg-replace]: Unknown modifier ']' in C:\xampp\htdocs\1.php on line 4 Link to comment https://forums.phpfreaks.com/topic/162662-find-and-delete-strings/#findComment-858625 Share on other sites More sharing options...
xtopolis Posted June 18, 2009 Share Posted June 18, 2009 Uff, teach me to copypasta. I think it just needs delimiters on that line: $file = preg_replace('/<[^>]*>/','',$file); (I added slashes) edit, but im not sure that regex does what you want? Link to comment https://forums.phpfreaks.com/topic/162662-find-and-delete-strings/#findComment-858626 Share on other sites More sharing options...
akiznin Posted June 18, 2009 Author Share Posted June 18, 2009 omg, thank you so MUCH!! edit: how can i also delete in between ( and )? i replaced the arrows but it deletes everything.. Link to comment https://forums.phpfreaks.com/topic/162662-find-and-delete-strings/#findComment-858636 Share on other sites More sharing options...
Ken2k7 Posted June 18, 2009 Share Posted June 18, 2009 preg_replace(array('#<[^>]*>#','#\([^)]*\)#'),'',$str); Link to comment https://forums.phpfreaks.com/topic/162662-find-and-delete-strings/#findComment-858652 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.