URL encoding function
65 views (last 30 days)
I need to convert a string into a URL. I'm trying to use the urlencode function but it doesn't work properly, converting spaces to plus signs instead of the escape sequence %20. How can I convert the string properly, so space becomes %20 and other non-alphanumeric characters are replaced by their corresponding escape sequences?
Fangjun Jiang on 4 Aug 2011
Yes, it is weird. urlencode() is an one-line function. type "edit urlencode.m" to see if you can change the encoding method and then try again.
Morrie Gasser on 6 Feb 2017
If you are using the encoded result for a URI or URL, note that in R2016b there is a new class, matlab.net.URI, which may do the encoding you're looking for.
Muhammad Siddiqui on 26 Apr 2020
I'm trying to detect SQL injection in my course of Pattern Recognition. My algorithm would be as follows:-
1) Encode URL feeded by user (this step is feature detection)
2) Compare the URL with the dataset of false URL.
3) Accordingly, classify whether URL is vulnerable or otherwise.
Please help me in writing code for above-stated steps. Prompt assistance is requested
Bereketab Gulai on 28 Apr 2020
Edited: Bereketab Gulai on 28 Apr 2020
Here is an anternative,
report = getReport(x, 'extended', 'hyperlinks', 'off');
% Take some of the report beginning, replace
% spaces, they will be encoded (NOTE: potential other things may be encoded which could fail)
reportBeginningText = strrep(extractBetween(report, 1, 10), ' ', '%20');
% mlreportgen.utils.fileToURI is the only correct provider of encoded path, I suppose.
% However, "file:/c:/some/path" needs to be removed
formattedReport = reportBeginningText + extractAfter(mlreportgen.utils.fileToURI(report), reportBeginningText);
This example was used with mailto URL.