Page 1 of 1
search & replace
Posted: Wed Oct 07, 2015 5:36 pm
by Vegan
can php do basic text editing with search and replace in a file loaded into an array or something like that?
Re: search & replace
Posted: Wed Oct 07, 2015 6:21 pm
by requinix
Yup.
Re: search & replace
Posted: Wed Oct 07, 2015 6:25 pm
by Celauran
Can you be a little more specific? What is it you're trying to do?
Re: search & replace
Posted: Sun Oct 11, 2015 3:16 pm
by Vegan
I was looking at cleaning up POST forms before feeding them to a database
Re: search & replace
Posted: Mon Oct 12, 2015 10:03 am
by Christopher
Use str_replace() for simple replacements. And preg_replace() for more complex matching. There are functions like trim() for additional cleanup. And, of course, escape the data with the database's escaping method before writing to the database.
There are also special-case cleanups. For example, str_replace(array("\n", "\r", "\t"), '', $data) for saving data that may later be exported to a tab delimited file (e.g. SELECT OUTFILE).
Re: search & replace
Posted: Sun Nov 01, 2015 10:53 am
by Vegan
Excel is hard pressed with tab delimited so I tend to prefer another type of delimiter