PHP, escape any characters [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Can I escape any character in string without using symbol "\"?
For example, programming language C# allows specify string, which does not have special characters:
#"c:\webserver\".Equals("c:\\webserver\\") // <== return true
Thanks for answers and sorry for my poor English!

to escape use addslashes(); and stripslashes() to remove added slashes

Do you want to automatically add slashes?
Then you can use built in php function:
addslashes();
http://php.net/manual/en/function.addslashes.php

Related

Regex (.*) and random string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I changed the Permalink on WP to get any strings after the path. I use the regex: "yourdomain.com/%postname%-(.*)/"
When I am checking: "yourdomain.com/%postname%-f46eb54b99ce3a9835ea7d63e075d434", it matches.
But when I check:
"yourdomain.com/%postname%-446eb54b99ce3a9835ea7d63e075d434" then it returns "yourdomain.com/%postname%-(.*)/446/".
I think (. *) Will fit in everything, regardless of letters or numbers. I appreciate anyone who can explain it to me.
You should escape all / and ., if you mean them as normal symbols. So, you'll have:
yourdomain\.com\/%postname%-(.*)\/
It must not match
yourdomain.com/%postname%-f46eb54b99ce3a9835ea7d63e075d434
or
yourdomain.com/%postname%-446eb54b99ce3a9835ea7d63e075d434
, because you regex demands / at the end. If it is not obligatory, put ? after the ending \/.
yourdomain\.com\/%postname%-(.*)\/?
tests

Prepend and append to each variable [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
First question here!
I have some PHP variables all in the form of the below, in around 7/8 different files.
$this->do['string']
I wish to make them all into the following:
myfunction($this->do['string'])
I understand I have to use regex and the get file contents function, but I'm unsure where to go from here! Would be very grateful if someone can assist!
Thanks in advance
How about:
$result = preg_replace("/(\$this->do\['[^']+'\])/", "myfunction($1)", $inputstring);
Edit according to comment:
In the comment you said that your input string is: $inputstring = "\$this->do['fsdfs']"; (with a backslash before $this). You have then to add the backslash in the regex and also escape it, so the whole instruction becomes:
$result = preg_replace("/(\\\$this->do\['[^']+'\])/", "myfunction($1)", $inputstring);
// ^^^

Is FILTER_SANITIZE_URL useless? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
The documentation says:
Remove all characters except letters, digits and $-_.+!*'(),{}|\^~[]`<>#%";/?:#&=.
What's the point of using it if it allows quotes and stuff? I can just close the href attribute with " then put some JavaScript. Heck, I can put JavaScript even inside the URL.
It makes sure that the URL is valid. Protecting your presentation layer is up to you through use of well-known, battle-tested sanitization routines.

Regex improvement [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have the following regex:
/%%[\s\S]*?%%/i
It's meant to catch these types of strings:
%%test%%
%%test2%%
However, because this regex runs on big strings, sometimes there are mistakes, for example if i have this:
%test%% adhja kshdjah skdja %%test1%% it will return %% adhja kshdjah skdja %%
The strings that it is supposed to catch never have any spaces in them, how can I alter my regex to take only the ones with no spaces?
Use [^%\s] for non space and non %.
/%%[^%\s]*?%%/

write special string to url [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
how to write special string such as %31 to url.
Your tags suggest a bit of indecisiveness when it comes to the language you are using, so I'll assume PHP.
Use the urlencode function to escape illegal and special characters for inclusion in a URL.
You just need to encode the % to %25 - so %31 turns to %2531.
Just lookup any ASCII table for the decimal value of the character.
Just encode the percent sign itself so that when the browser parses the string it translates it properly.
Here's a link with various characters and their encoding:
http://www.blooberry.com/indexdot/html/topics/urlencoding.htm
urlencode is probably your friend :)

Categories