How do I get to strip a url and put it back in the same position?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
Jeff Atwood had an informative post regarding the issues you might face with this.
Regardless of the programming language and libraries you use, you will have problems with some cases, e.g., --http://www.codinghorror.com/blog/archives/001181.html-- when using a straightforward regex substitution.
I don't use PHP very often, but the issue boils down to trying to figure out the pattern to use in the preg_replace call.
Use regular expressions.. you can easily detect the URL using regexs.
Detecting a URL
Replacing a Pattern
If you're wanting to put the same URL back into its initial position, why do you want to remove it in the first place/ what exactly are you trying to do. A little more context would help us help you.
you're probably looking for [
preg_replace_callback
](http://www.php.net. /preg_replace_callback).it simply matches a regular expression pattern, gives the result to a function you provide, and replaces the original match with its return value.
There are not many ways to regexp an url that is compliant with rfc3986
As a C string, the regex will be:
Where the enum denotes what capture indexes correspond to which url parts.