search & replace
Moderator: General Moderators
search & replace
can php do basic text editing with search and replace in a file loaded into an array or something like that?
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
My site is powered by LAMP
Re: search & replace
Yup.
Re: search & replace
Can you be a little more specific? What is it you're trying to do?
Re: search & replace
I was looking at cleaning up POST forms before feeding them to a database
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
My site is powered by LAMP
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: search & replace
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).
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).
(#10850)
Re: search & replace
Excel is hard pressed with tab delimited so I tend to prefer another type of delimiter
Hardcore Games™ Legendary is the Only Way to Play™
My site is powered by LAMP
My site is powered by LAMP