Here’s my problem: Essentially I need to use an XML file from an external source and loop it through to display nicely some data. I created a function that gets content from the external URL (file_get_contents), then I turn the string of XML into an object (I use LIBXML_NOCDATA as a parameter because it contains ), right after I turn
Tag: sanitization
Remove blacklisted terms from string then eliminate unnecessary spaces
I have an array of blacklisted terms: and I have a string to sanitize: I just want to remove the $arrayBlacklist value if it’s in the $city variable. So, I get $city = “Jakarta Selatan” Answer Sort the array based on string length to avoid overlapping issues using usort. preg_replace each of the string in a case-insensitive manner. Finally, remove
How can I sanitize laravel Request inputs?
I have MyRequest.php class extending AppHttpRequestsRequest. I want to trim() every input before validation because an e-mail with a space after it does not pass validation. However sanitize() was …
Sanitize file path in PHP without realpath()
Is there a way to safely sanitize path input, without using realpath()? Aim is to prevent malicious inputs like ../../../../../path/to/file $handle = fopen($path . ‘/’ . $filename, ‘r’);
Sanitize $_SERVER[‘HTTP_USER_AGENT’] & $_SERVER[‘HTTP_REFERER’] before saving to DB?
I have a feedback form which will take a couple of user inputted fields along with a few fields generated by PHP functions like ‘user-agent’ and ‘referer.’ My question is should these strings be sanitized before being inputted? I realize one could easily alter the user-agent and the referring page, but could it be possible for a visitor to add
Sanitizing HTML input
I’m thinking of adding a rich text editor to allow a non-programmer to change the aspect of text. However, one issue is that it’s possible to distort the layout of a rendered page if the markup is incorrect. What’s a good lightweight way to sanitize html? Answer You will have to decide between good and lightweight. The recommended choice is
PHP input sanitizer function?
What’s a method to sanitize PHP POST data for passing to a mail function? (I prefer a method that’s not part of the mysql_function() family of functions.) I take the data, sanitize it, print it back to the user and send it in an email to a preset address. EDIT: I’m just sending the email to our email address so
Strip all non-alphanumeric, spaces and punctuation symbols from a string
How can I use PHP to strip out all characters that are NOT letters, numbers, spaces, or punctuation marks? I’ve tried the following, but it strips punctuation. Answer Example: p{P} matches all Unicode punctuation characters (see Unicode character properties). If you only want to allow specific punctuation, simply add them to the negated character class. E.g: