mirror of
https://github.com/natelandau/shell-scripting-templates.git
synced 2025-11-08 13:13:47 -05:00
function to decode HTML special characters
This commit is contained in:
@@ -514,22 +514,29 @@ progressBar() {
|
||||
tput cnorm
|
||||
}
|
||||
|
||||
# URL encoding/decoding from: https://gist.github.com/cdown/1163649
|
||||
urlencode() {
|
||||
# urlencode <string>
|
||||
htmlDecode() {
|
||||
# Decode HTML characters with sed
|
||||
# Usage: htmlDecode <string>
|
||||
echo "${1}" | sed -f "${SOURCEPATH}/htmlDecode.sed"
|
||||
}
|
||||
|
||||
local length="${#1}"
|
||||
for (( i = 0; i < length; i++ )); do
|
||||
local c="${1:i:1}"
|
||||
case $c in
|
||||
[a-zA-Z0-9.~_-]) printf "$c" ;;
|
||||
*) printf '%%%02X' "'$c"
|
||||
esac
|
||||
done
|
||||
|
||||
urlencode() {
|
||||
# URL encoding/decoding from: https://gist.github.com/cdown/1163649
|
||||
# Usage: urlencode <string>
|
||||
|
||||
local length="${#1}"
|
||||
for (( i = 0; i < length; i++ )); do
|
||||
local c="${1:i:1}"
|
||||
case $c in
|
||||
[a-zA-Z0-9.~_-]) printf "$c" ;;
|
||||
*) printf '%%%02X' "'$c"
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
urldecode() {
|
||||
# urldecode <string>
|
||||
# Usage: urldecode <string>
|
||||
|
||||
local url_encoded="${1//+/ }"
|
||||
printf '%b' "${url_encoded//%/\x}"
|
||||
|
||||
Reference in New Issue
Block a user