Krydos Posted November 19, 2017 Posted November 19, 2017 # cat lineendings.txt text\\r\\n this doesn't look right\\r\\n # sed -i 's/\\\\r\\\\n/\\r\\n/g' lineendings.txt # cat lineendings.txt text\r\n this doesn't look right\r\n # The -i flag means "in place" so it overwrites the original file. The comical number of slashes (and backslahes) is because you need to escape each \ in regex.
ridoy Posted November 19, 2017 Author Posted November 19, 2017 Well, I didn't get what that means 😜
Krydos Posted November 19, 2017 Posted November 19, 2017 # is a linux root command prompt (not that you need root privileges to do this, I just happen to be using root right now), and those are commands on the prompt. cat is a command that prints the contents of files to the console. sed is a nifty little command that uses regex to change ouput, in this case a file.
ridoy Posted November 19, 2017 Author Posted November 19, 2017 When I get user input and add into mysql table with trim() function. It shows likeHi\r\nI am ridoyon PhpMyAdminWhen I print this out with nl2br function it shows same like above.
Krydos Posted November 19, 2017 Posted November 19, 2017 Well, sanitizing your mysql data is a really necessary thing to get in the practice of doing. Figure out what the minimum number of characters that you want people to be able to use, and then do something like this:$input = preg_replace("/[^a-zA-Z ]+/", "", $_POST["input"]); What that does is deletes anything that is not lowercase letters, uppercase letters, or spaces. Relevant xkcd: https://xkcd.com/327/
ridoy Posted November 19, 2017 Author Posted November 19, 2017 I just need to fix line break issue. Showing \r\n even while using inside the function of nl2br. All that I want tell you nl2br is not working (maybe).
ridoy Posted November 19, 2017 Author Posted November 19, 2017 I tried your code. Instead of removing \r\n is replaced with rn
Krydos Posted November 19, 2017 Posted November 19, 2017 What that does is deletes anything that is not lowercase letters, uppercase letters, or spaces.That's exactly what it's supposed to do. Remove everything that isn't lowercase letters, uppercase letters, or spaces. $input = preg_replace("/\\\\r\\\\n/", "\r\n", $_POST["input"]); !!!WARNING!!!: THE ABOVE CODE DOES NOT SANITIZE PROPERLY TO PREVENT SQL INJECTION! That might do what you want. It hasn't been tested.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now