Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialHanna Han
4,105 PointsReplace usage
Hi,
I don't really get why we need to use the function of Replace. I understand the concept of Replace function but I still have doubt of its necessity and usage in effective way in handling database. Could you give me more better example in detail?
2 Answers
Steven Parker
231,198 PointsI thought the video example was quite practical. Another one might be if you wanted to display addresses but spell out the word "Street" where the stored address has it abbreviated:
SELECT REPLACE(address, 'St.', 'Street') as Address FROM subscribers;
Whether it is "necessary" will depend on what is stored in the database, and in many cases it may not be.
Dennis Amiel Domingo
17,813 PointsThis is just a guess since I haven't reached the "Integrating PHP with Databases" yet. But I think this can be useful when you're handling user inputs. You can have them standardized not just for viewing purposes, but for functions, variables, or even arrays in PHP that need uniform data. Or maybe if you're copying them to another database, the REPLACE function can be useful in standardizing the data.