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 :)
Related
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 need to remove this string
page=x
x being a dynamic string (should be a number but can be anything)
from another string, for example
url/?filter=value&page=2&filter2=value
but it can also be:
url/?page=2
So, these are the cases as examples
1. url/?page=2&filter=value
2. url/?page=2
3. url/?filter=value&page=2
4. url/?filter=value&page=2&filter2=value
And they should return:
1. url/?filter=value
2. url/
3. url/?filter=value
4. url/?filter=value&filter2=value
How can I do that with regex?
You've said:
[?&]page=[^&]+
works for you. This will look for an ? or & then page= and anything after it until an &. A bit longer answer though is:
echo rtrim(preg_replace('/([?&])page=[^&]*&?/', '$1', $string), '&?')
which will correctly handle the intro and ending parameter cases.
Demo: https://3v4l.org/SupbH
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
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 6 years ago.
Improve this question
I want to create a regex that finds § in a string.
The section sign has unicode U+00A7 ,html sect and ascii value 245;
But I wonder if /(\245)/ would work
245 sits outside the ASCII character set (which is 7-bit), so I'm not sure where that value is from?
For the purposes of matching with preg_match, you can either just include the value as-is within the regex, or if you prefer not to, use \x{A7}.
This § is 167 decimal (take your pick):
as octal \0247
as hex \xA7
Either one can be used as a literal in regular expressions.
Unicode starts at characters >= 0x100, so you probably don't need the
Unicode modifier form //u unless PHP redefines Unicode.
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 7 years ago.
Improve this question
I have a feed that pulls from social feeds. These feeds can sometimes include special characters such as emojis that don't translate well:
I just want to strip out any characters that can't be displayed. I know that might remove a few that I could want but that's fine. I know I can do a regex but not really sure how to target like what's in the photo.
---EDIT---
This is what is throwing the characters above:
Try using PHP Sanitize Filters, most specifically FILTER_SANITIZE_SPECIAL_CHARS
<?php
$a = 'text including "unprintable" characters';
$sanitized_a = filter_var($a, FILTER_SANITIZE_SPECIAL_CHARS);
echo $sanitized_a;
?>
Just be careful using this if there are some characters you want (like < and > for instance)! Check the link at the top for a full list of filters you can choose from.
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